Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Serverless With
Lambda, NodeJS and ClaudiaJS
AWSome Meetup on 31st of October
Hi, I’m Riza
Serverless
“A new cloud compu!ng trend
that changes the way you think
about wri!ng and maintaining
applica!ons.”
Tomasz Janczuk
Chief...
“The essence of
the serverless trend is the
absence of the server
concept during so"ware
development.”
Tomasz Janczuk
Chie...
Faas
Amazon Lambda
Google Func!ons
Azure Func!ons
GOTO; Conf 2017
"For 400.000 ac!ve user we have paid $0.53 for
Lambda. Now, beat that with your hos!ng cost!"
Gojko Adzic ...
I’m sold!
Really?
ButILove’em
Especially this
Don’t you worry
*Fully-managed your serverless architecture
*Required to use CloudForma"on
*Build-in support for CI/CD workflows
* Golang-based framework
* Deployment op"mized
* Concurrent for quick deploy
* Deployment u"lity, not a framework
* Extensions for new features
* unit-test Lambda func"ons
“Serverless is like ice cream.
It’s nice to talk about it, but
much be"er to try out.”
The Casts
A Serverless Host
Deployment Library
Services
Database
The Architecture
First Act...

Ac!on!!
$ vim ~/.aws/credentials
[default]
aws_access_key_id = YOUR_ACCESS_KEY
aws_secret_access_key = YOUR_...
Second Act...

Install Claudia
$ npm install -g claudia
Third Act...

Write our service
$ mkdir claudia-icecream-shop
$ cd claudia-icecream-shop
$ npm init
$ npm install aws-sdk ...
Third Act...

Write our service
const ApiBuilder = require('claudia-api-builder')
const AWS = require('aws-sdk')
const api...
Third Act...

Write our service
api.post('/icecreams',
request 
=> {
const params = {
TableName: TABLENAME,
Item: {
icecre...
Third Act...

Write our service
api.get('/icecreams', request 
=> {
return dynamoDb
.scan({ TableName: TABLENAME })
.promi...
Fourth Act...

Setup DynamoDB
$ mkdir policy
$ vim policy/dynamodb-policy.json
Fourth Act...

Setup DynamoDB
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"dynamodb:DeleteItem",
"dynamodb:Get...
Fourth Act...

Setup DynamoDB
Fourth Act...

Setup DynamoDB
$ aws dynamodb create-table 
--table-name
icecreams 
--attribute-definition 
AttributeName=i...
Fi"h Act...

Time for deploy
$ claudia create 
--region ap-southeast-1 

--api-module index 
--policies policy
Fi"h Act...

Time for deploy
{
"lambda": {
"role": "ice-cream-shop-executor",
"name": "ice-cream-shop",
"region": "us-east...
$ curl -H "Content-Type: application/json"
-X POST -d
‘{“icecreamId”:”123","name":"chocolate"}' 
https:
//xxx.execute-api....
Sixth Act...

Trying it out
$ curl https:
//xxx.execute-api.ap-
southeast-1.amazonaws.com/latest/icecreams
[{“icecreamId”:...
Seventh Act...

Some updates
$ claudia update
That’s Pretty much it!
Now go, you deserve some ice
cream!
h!ps://github.com/rizafahmi/claudia-ice-cream
Upcoming SlideShare
Loading in …5
×

AWS Lambda with ClaudiaJS

255 views

Published on

Easy deployment to AWS Lambda With ClaudiaJS

Published in: Technology
  • Be the first to comment

AWS Lambda with ClaudiaJS

  1. 1. Serverless With Lambda, NodeJS and ClaudiaJS AWSome Meetup on 31st of October
  2. 2. Hi, I’m Riza
  3. 3. Serverless
  4. 4. “A new cloud compu!ng trend that changes the way you think about wri!ng and maintaining applica!ons.” Tomasz Janczuk Chief Architect for Webtasks at Auth0
  5. 5. “The essence of the serverless trend is the absence of the server concept during so"ware development.” Tomasz Janczuk Chief Architect for Webtasks at Auth0
  6. 6. Faas Amazon Lambda Google Func!ons Azure Func!ons
  7. 7. GOTO; Conf 2017 "For 400.000 ac!ve user we have paid $0.53 for Lambda. Now, beat that with your hos!ng cost!" Gojko Adzic from MindMup Designing for the Serverless Age h!ps://www.youtube.com/watch?v=w7X4gAQTk2E
  8. 8. I’m sold!
  9. 9. Really?
  10. 10. ButILove’em
  11. 11. Especially this
  12. 12. Don’t you worry
  13. 13. *Fully-managed your serverless architecture *Required to use CloudForma"on *Build-in support for CI/CD workflows
  14. 14. * Golang-based framework * Deployment op"mized * Concurrent for quick deploy
  15. 15. * Deployment u"lity, not a framework * Extensions for new features * unit-test Lambda func"ons
  16. 16. “Serverless is like ice cream. It’s nice to talk about it, but much be"er to try out.”
  17. 17. The Casts A Serverless Host Deployment Library Services Database
  18. 18. The Architecture
  19. 19. First Act...
 Ac!on!! $ vim ~/.aws/credentials [default] aws_access_key_id = YOUR_ACCESS_KEY aws_secret_access_key = YOUR_ACCESS_SECRET
  20. 20. Second Act...
 Install Claudia $ npm install -g claudia
  21. 21. Third Act...
 Write our service $ mkdir claudia-icecream-shop $ cd claudia-icecream-shop $ npm init $ npm install aws-sdk claudia-api-builder $ vim index.js
  22. 22. Third Act...
 Write our service const ApiBuilder = require('claudia-api-builder') const AWS = require('aws-sdk') const api = new ApiBuilder() const dynamoDb = new AWS.DynamoDB.DocumentClient() const TABLENAME = 'icecreams'
  23. 23. Third Act...
 Write our service api.post('/icecreams', request => { const params = { TableName: TABLENAME, Item: { icecreamid: request.body.id, name: request.body.name } } return dynamoDb.put(params).promise() }, { success: 201 } )
  24. 24. Third Act...
 Write our service api.get('/icecreams', request => { return dynamoDb .scan({ TableName: TABLENAME }) .promise() .then(response => response.Items) }) module.exports = api
  25. 25. Fourth Act...
 Setup DynamoDB $ mkdir policy $ vim policy/dynamodb-policy.json
  26. 26. Fourth Act...
 Setup DynamoDB { "Version": "2012-10-17", "Statement": [ { "Action": [ "dynamodb:DeleteItem", "dynamodb:GetItem", "dynamodb:PutItem", "dynamodb:Scan" ], "Effect": "Allow", "Resource": "*" } ] }
  27. 27. Fourth Act...
 Setup DynamoDB
  28. 28. Fourth Act...
 Setup DynamoDB $ aws dynamodb create-table --table-name icecreams --attribute-definition AttributeName=icecreamid,AttributeType=S --key-schema AttributeName=icecreamid,KeyType=HASH --provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1 --region ap-southeast-1 --query TableDescription.TableArn --output text
  29. 29. Fi"h Act...
 Time for deploy $ claudia create --region ap-southeast-1 --api-module index --policies policy
  30. 30. Fi"h Act...
 Time for deploy { "lambda": { "role": "ice-cream-shop-executor", "name": "ice-cream-shop", "region": "us-east-1" }, "api": { "id": "your-service-id", "module": "index", "url": “https: //xxx.execute-api.ap- southeast-1.amazonaws.com/latest" } }
  31. 31. $ curl -H "Content-Type: application/json" -X POST -d ‘{“icecreamId”:”123","name":"chocolate"}' https: //xxx.execute-api.ap- southeast-1.amazonaws.com/latest/icecreams Sixth Act...
 Trying it out
  32. 32. Sixth Act...
 Trying it out $ curl https: //xxx.execute-api.ap- southeast-1.amazonaws.com/latest/icecreams [{“icecreamId”: 123, “name”: “chocolate”}]
  33. 33. Seventh Act...
 Some updates $ claudia update
  34. 34. That’s Pretty much it! Now go, you deserve some ice cream! h!ps://github.com/rizafahmi/claudia-ice-cream

×