More Related Content Similar to AWS Lambda with ClaudiaJS (20) More from Riza Fahmi (20) AWS Lambda with ClaudiaJS4. “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. “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
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
19. First Act...
Ac!on!!
$ vim ~/.aws/credentials
[default]
aws_access_key_id = YOUR_ACCESS_KEY
aws_secret_access_key = YOUR_ACCESS_SECRET
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. 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. 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. Third Act...
Write our service
api.get('/icecreams', request
=> {
return dynamoDb
.scan({ TableName: TABLENAME })
.promise()
.then(response
=> response.Items)
})
module.exports = api
26. Fourth Act...
Setup DynamoDB
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"dynamodb:DeleteItem",
"dynamodb:GetItem",
"dynamodb:PutItem",
"dynamodb:Scan"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
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. Fi"h Act...
Time for deploy
$ claudia create
--region ap-southeast-1
--api-module index
--policies policy
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. $ 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. Sixth Act...
Trying it out
$ curl https:
//xxx.execute-api.ap-
southeast-1.amazonaws.com/latest/icecreams
[{“icecreamId”: 123, “name”: “chocolate”}]
34. That’s Pretty much it!
Now go, you deserve some ice
cream!
h!ps://github.com/rizafahmi/claudia-ice-cream