Post on 11-Apr-2017
"Serverless" Express@AnnaGerber
Before you start
You’ll need:• An AWS account • An IAM user with permissions for AWS Lambda, API Gateway, CloudFormation, DynamoDB, S3 and CloudWatch• Recent version AWS-‐CLI installedhttps://aws.amazon.com/cli/
aws-‐serverless-‐express
Library for using AWS Lambda and Amazon API Gateway with Express
git clone https://github.com/awslabs/aws-‐serverless-‐express
See example directory for sample app
AWS Lambda
API Gateway
Cloud Formation
Example app
AWS SAM
• Serverless Application Model• JSON or YAML• Defines API Gateway APIs, Lambda functions, DynamoDB tables
Configure the Sample app
Setup
npm run setup
Cloud Formation Stack
Stack Outputs
Example app
DynamoDB
Persisting data to DynamoDB
To persist users to DynamoDB:• Add DynamoDB permissions to the role• Create DynamoDB table for storing users• Modify the CRUD routes in our Express app to use DynamoDB instead of in-‐memory array
Update role permission
Create Table Users
Modify the routes
• Add the AWS SDK for DynamoDB support• npm install -‐-‐save aws-‐sdk
var AWS = require("aws-‐sdk")var docClient = new AWS.DynamoDB.DocumentClient()
Create a User
List Users
List a specific User
Develop your API
• Continue to develop as for regular express app• Logs for the app can be accessed via CloudWatch• Edit package.json to ensure additional resources are packaged• To re-‐package and re-‐deploy the app:
• npm run package-‐deploy
• To tear down:• npm run delete-‐stack