aws lambda with claudiajs

34
Serverless With Lambda, NodeJS and ClaudiaJS AWSome Meetup on 31st of October

Upload: riza-fahmi

Post on 22-Jan-2018

173 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: AWS Lambda with ClaudiaJS

Serverless WithLambda, NodeJS and ClaudiaJS

AWSome Meetup on 31st of October

Page 2: AWS Lambda with ClaudiaJS

Hi, I’m Riza

Page 3: AWS Lambda with ClaudiaJS

Serverless

Page 4: AWS Lambda with ClaudiaJS

“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

Page 5: AWS Lambda with ClaudiaJS

“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

Page 6: AWS Lambda with ClaudiaJS

Faas

Amazon Lambda

Google Func!ons

Azure Func!ons

Page 7: AWS Lambda with ClaudiaJS

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

Page 8: AWS Lambda with ClaudiaJS

I’m sold!

Page 9: AWS Lambda with ClaudiaJS

Really?

Page 10: AWS Lambda with ClaudiaJS

But I Love’em

Page 11: AWS Lambda with ClaudiaJS

Especially this

Page 12: AWS Lambda with ClaudiaJS

Don’t you worry

Page 13: AWS Lambda with ClaudiaJS

*Fully-managed your serverless architecture

*Required to use CloudForma"on

*Build-in support for CI/CD workflows

Page 14: AWS Lambda with ClaudiaJS

* Golang-based framework

* Deployment op"mized

* Concurrent for quick deploy

Page 15: AWS Lambda with ClaudiaJS

* Deployment u"lity, not a framework

* Extensions for new features

* unit-test Lambda func"ons

Page 16: AWS Lambda with ClaudiaJS

“Serverless is like ice cream. It’s nice to talk about it, but

much be"er to try out.”

Page 17: AWS Lambda with ClaudiaJS

The Casts

A Serverless Host

Deployment Library

Services

Database

Page 18: AWS Lambda with ClaudiaJS

The Architecture

Page 19: AWS Lambda with ClaudiaJS

First Act...Ac!on!!

$ vim ~/.aws/credentials

[default] aws_access_key_id = YOUR_ACCESS_KEY aws_secret_access_key = YOUR_ACCESS_SECRET

Page 20: AWS Lambda with ClaudiaJS

Second Act...Install Claudia

$ npm install -g claudia

Page 21: AWS Lambda with ClaudiaJS

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

Page 22: AWS Lambda with ClaudiaJS

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'

Page 23: AWS Lambda with ClaudiaJS

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 } )

Page 24: AWS Lambda with ClaudiaJS

Third Act...Write our service

api.get('/icecreams', request => { return dynamoDb .scan({ TableName: TABLENAME }) .promise() .then(response => response.Items) })

module.exports = api

Page 25: AWS Lambda with ClaudiaJS

Fourth Act...Setup DynamoDB

$ mkdir policy

$ vim policy/dynamodb-policy.json

Page 26: AWS Lambda with ClaudiaJS

Fourth Act...Setup DynamoDB

{ "Version": "2012-10-17", "Statement": [ { "Action": [ "dynamodb:DeleteItem", "dynamodb:GetItem", "dynamodb:PutItem", "dynamodb:Scan" ], "Effect": "Allow", "Resource": "*" } ] }

Page 27: AWS Lambda with ClaudiaJS

Fourth Act...Setup DynamoDB

Page 28: AWS Lambda with ClaudiaJS

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

Page 29: AWS Lambda with ClaudiaJS

Fi"h Act...Time for deploy

$ claudia create --region ap-southeast-1 \

--api-module index --policies policy

Page 30: AWS Lambda with ClaudiaJS

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"

}

}

Page 31: AWS Lambda with ClaudiaJS

$ 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

Page 32: AWS Lambda with ClaudiaJS

Sixth Act...Trying it out

$ curl https: //xxx.execute-api.ap-

southeast-1.amazonaws.com/latest/icecreams

[{“icecreamId”: 123, “name”: “chocolate”}]

Page 33: AWS Lambda with ClaudiaJS

Seventh Act...Some updates

$ claudia update

Page 34: AWS Lambda with ClaudiaJS

That’s Pretty much it!Now go, you deserve some ice cream!

h!ps://github.com/rizafahmi/claudia-ice-cream