aws lambda with claudiajs

Download AWS Lambda with ClaudiaJS

Post on 22-Jan-2018

146 views

Category:

Technology

3 download

Embed Size (px)

TRANSCRIPT

  • Serverless WithLambda, NodeJS and ClaudiaJS

    AWSome Meetup on 31st of October

  • Hi, Im Riza

  • Serverless

  • 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

  • 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

  • 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 from MindMup

    Designing for the Serverless Age

    h!ps://www.youtube.com/watch?v=w7X4gAQTk2E

  • Im sold!

  • Reall

    y?

  • But I Lov

    eem

  • Especially this

  • Dont 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. Its 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_ACCESS_SECRET

  • 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 claudia-api-builder $ vim index.js

  • 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'

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

  • Third Act...Write our service

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

    module.exports = api

  • Fourth Act...Setup DynamoDB

    $ mkdir policy

    $ vim policy/dynamodb-policy.json

  • Fourth Act...Setup DynamoDB

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

  • Fourth Act...Setup DynamoDB

  • 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

  • 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-1"

    },

    "api": {

    "id": "your-service-id",

    "module": "index",

    "url": https://xxx.execute-api.ap-

    southeast-1.amazonaws.com/latest"

    }

    }

  • $ 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

  • Sixth Act...Trying it out

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

    southeast-1.amazonaws.com/latest/icecreams

    [{icecreamId: 123, name: chocolate}]

  • Seventh Act...Some updates

    $ claudia update

  • Thats Pretty much it!Now go, you deserve some ice cream!

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