SlideShare une entreprise Scribd logo
1  sur  41
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS re:INVENT
Authoring and Deploying Serverless
Applications with AWS SAM
O r r W e i n s t e i n – S r . P r o d u c t M a n a g e r – A W S L a m b d a
S R V 3 1 1
D e c e m b e r 1 , 2 0 1 7
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Agenda
- Intro
- Dev iteration loop
- Author (application and code)
- Test
- Debug
- Serverless Deployments
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Serverless applications
ANYTHING
Changes in
data state
Requests to
endpoints
Changes in
resource state
EVENT SOURCE FUNCTION
Node.js
Python
Java
C#
Go – Coming soon!
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Serverless means…
No servers to provision
or manage
Scales with usage
Never pay for idle Availability and fault
tolerance built in
FINRA
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Running for over 18 months, at 4,000+ requests per second
Low latency processing
No action required to handle fluctuations in scale
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
ALM for serverless applications
Author Build Test DeployDebugTest
CI/CD
Source
Author/test/debug
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Author/test/debug
Author Test Debug
Simple app
No team members
No code repo
What if:
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
New and improved Lambda console
Cloud9 editor within the Lambda console
Function graph
Persisted test events
Monitoring view (jump to logs for any timeframe)
New
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Demo #1: Author, test and
debug in the Lambda
console
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Tips - Lambda console editor
- Useful keyboard shortcuts
- Full screen Cmd + Shift + F
- Cache file locally Cmd + S
- Save (UpdateFunctionCode) Cmd + Shft + U
- Test Cmd + I
- Configure test events Cmd + J
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Author/Test/Debug cycle
Author
C o d e A p p l i c a t i o n
Test Debug
Meet
SAM!
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Serverless Application Model (SAM)
CloudFormation extension optimized for serverless
New serverless resource types: functions, APIs, and tables
Supports anything CloudFormation supports
Open specification (Apache 2.0)
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
CloudFormation
Provision and manage a collection of related AWS resources.
Your application = CloudFormation stack
Input .yaml file and output provisioned AWS resources
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWSTemplateFormatVersion: '2010-09-09’
Transform: AWS::Serverless-2016-10-31
Resources:
GetHtmlFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://demo-bucket/todo_list.zip
Handler: index.js
Runtime: nodejs6.1
Policies: AmazonDynamoDBReadOnlyAccess
Events:
GetHtml:
Type: Api
Properties:
Path: /{proxy+}
Method: ANY
SAM template
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWSTemplateFormatVersion: '2010-09-09’
Transform: AWS::Serverless-2016-10-31
Resources:
GetHtmlFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://demo-bucket/todo_list.zip
Handler: index.js
Runtime: nodejs6.1
Policies: AmazonDynamoDBReadOnlyAccess
Events:
GetHtml:
Type: Api
Properties:
Path: /{proxy+}
Method: ANY
SAM template
AWS::Lambda::Function
AWS::IAM::Role
AWS::IAM::Policy
AWS::ApiGateway::RestApi
AWS::ApiGateway::Stage
AWS::ApiGateway::Deployment
AWS::Lambda::Permission
CloudFormation template
AWSTemplateFormatVersion: '2010-09-09'
Resources:
GetHtmlFunctionGetHtmlPermissionProd:
Type: AWS::Lambda::Permission
Properties:
Action: lambda:invokeFunction
Principal: apigateway.amazonaws.com
FunctionName:
Ref: GetHtmlFunction
SourceArn:
Fn::Sub: arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${ServerlessRestApi}/Prod/ANY/*
ServerlessRestApiProdStage:
Type: AWS::ApiGateway::Stage
Properties:
DeploymentId:
Ref: ServerlessRestApiDeployment
RestApiId:
Ref: ServerlessRestApi
StageName: Prod
ListTable:
Type: AWS::DynamoDB::Table
Properties:
ProvisionedThroughput:
WriteCapacityUnits: 5
ReadCapacityUnits: 5
AttributeDefinitions:
- AttributeName: id
AttributeType: S
KeySchema:
- KeyType: HASH
AttributeName: id
GetHtmlFunction:
Type: AWS::Lambda::Function
Properties:
Handler: index.gethtml
Code:
S3Bucket: flourish-demo-bucket
S3Key: todo_list.zip
Role:
Fn::GetAtt:
- GetHtmlFunctionRole
- Arn
Runtime: nodejs4.3
GetHtmlFunctionRole:
Type: AWS::IAM::Role
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AmazonDynamoDBReadOnlyAccess
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
ServerlessRestApiDeployment:
Type: AWS::ApiGateway::Deployment
Properties:
RestApiId:
Ref: ServerlessRestApi
Description: 'RestApi deployment id: 127e3fb91142ab1ddc5f5446adb094442581a90d'
StageName: Stage
GetHtmlFunctionGetHtmlPermissionTest:
Type: AWS::Lambda::Permission
Properties:
Action: lambda:invokeFunction
Principal: apigateway.amazonaws.com
FunctionName:
Ref: GetHtmlFunction
SourceArn:
Fn::Sub: arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${ServerlessRestApi}/*/ANY/*
ServerlessRestApi:
Type: AWS::ApiGateway::RestApi
Properties:
Body:
info:
version: '1.0'
title:
Ref: AWS::StackName
paths:
"/{proxy+}":
x-amazon-apigateway-any-method:
x-amazon-apigateway-integration:
httpMethod: ANY
type: aws_proxy
uri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-
31/functions/${GetHtmlFunction.Arn}/invocations
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Author
C o d eA p p l i c a t i o n
Author/Test/Debug cycle
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS Cloud9
Cloud-based dev environment
Write, test and debug with just a browser
Optimized for serverless
New
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
C o d eA p p l i c a t i o n
Test Debug
Author/Test/Debug cycle
Wait, what about test
and debug?
Author
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Testing serverless apps - challenges
- Test in an environment that resembles Lambda:
- OS
- Libraries
- Runtime
- Configured limits (memory, timeout)
- Mimic response and log outputs
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Testing serverless apps - challenges
- Test events need to be:
- Syntactically accurate
- Different for each trigger
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Testing serverless apps - challenges
{
"Records": [
{
"eventVersion": "2.0",
"eventTime": "1970-01-01T00:00:00.000Z",
"requestParameters": {
"sourceIPAddress": "127.0.0.1"
},
"s3": {
"configurationId": "testConfigRule",
"object": {
"eTag":
"0123456789abcdef0123456789abcdef",
"sequencer": "0A1B2C3D4E5F678901",
"key": "myKey",
"size": 1024
},
"bucket": {
"arn": "arn:aws:s3:::myBucket",
"name": "myBucket",
"ownerIdentity": {
"principalId": "EXAMPLE"
}
},
"s3SchemaVersion": "1.0"
},
"responseElements": {
"x-amz-id-2":
"EXAMPLE123/5678abcdefghijklambdaisawesome/mnop
qrstuvwxyzABCDEFGH",
"x-amz-request-id": "EXAMPLE123456789"
},
"awsRegion": "us-east-1",
"eventName": "ObjectCreated:Put",
"userIdentity": {
"principalId": "EXAMPLE"
},
"eventSource": "aws:s3” } ] }
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Introducing SAM Local
CLI tool for local testing of serverless apps
Leverages Docker images to mimic Lambda’s
execution environment
Emulates Lambda functions and APIs
Event generator to help you generate event
payload for common Lambda triggers
sam local generate-event s3 --bucket <bucket> --key <key>
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Introducing SAM Local
Response object and function logs available
on your local machine
Supports live debugging
Currently supports Java, Node.js and Python
SAM Local is open source & accepting pull
requests!
https://github.com/awslabs/aws-sam-local
npm install –g aws-sam-local
$ sam --help
NAME:
sam -
___ _____ ___ _ __ __
/_  / / __| / __| /_ | / |
/ _  // /__  __ / _ | |/| |
/_/ __/_/ |___/ |___/_/ __| |_|
AWS Serverless Application Model (SAM) CLI
The AWS Serverless Application Model extends AWS CloudFormation to provide a simplified way of defining the Amazon API Gateway APIs, AWS Lambda functions,
and Amazon DynamoDB tables needed by your serverless application. You can find more in-depth guide about the SAM specification
here:nhttps://github.com/awslabs/serverless-application-model.
USAGE:
sam [global options] command [command options] [arguments...]
VERSION:
0.2.0
COMMANDS:
local Run your Serverless application locally for quick development & testing
validate Validates an AWS SAM template. If valid, will print a summary of the resources found within the SAM template. If the template is invalid, returns
a non-zero exit code.
package Package an AWS SAM application. This is an alias for 'aws cloudformation package'.
deploy Deploy an AWS SAM application. This is an alias for 'aws cloudformation deploy'.
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--help, -h show help
--version, -v print the version
$ sam local --help
..
USAGE:
sam local command [command options] [arguments...]
COMMANDS:
start-api Allows you to run your Serverless application locally for quick development & testing. When run in a
directory that contains your Serverless functions and your AWS SAM template, it will create a local HTTP server
hosting all of your functions. When accessed (via browser, cli etc), it will launch a Docker container locally to
invoke the function. It will read the CodeUri property of AWS::Serverless::Function resource to find the path in your
file system containing the Lambda Function code. This could be the project's root directory for interpreted languages
like Node & Python, or a build directory that stores your compiled artifacts or a JAR file. If you are using a
interpreted language, local changes will be available immediately in Docker container on every invoke. For more
compiled languages or projects requiring complex packing support, we recommended you run your own building solution
and point SAM to the directory or file containing build artifacts.
invoke Invokes a local Lambda function once and quits after invocation completes.
Useful for developing serverless functions that handle asynchronous events (such as S3/Kinesis etc), or if you want
to compose a script of test cases. Event body can be passed in either by stdin (default), or by using the --event
parameter. Runtime output (logs etc) will be outputted to stderr, and the Lambda function result will be outputted to
stdout.
generate-event Generates Lambda events (e.g. for S3/Kinesis etc) that can be piped to 'sam local invoke'
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Demo #2: Author, test &
debug in AWS Cloud9
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Author
C o d eA p p l i c a t i o n
Test Debug
Author/Test/Debug cycle
</>
GitHub
Amazon S3
AWS CodeCommit
AWS CodeBuild AWS CodeBuild
Third-party tools
AWS CloudFormation
Source Build Test Deploy
Deploying serverless applications
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Safe deployments baked into SAM!
Lambda aliases now enable traffic shifting
CodeDeploy integration for deployment automation
Deployment automation natively supported in SAM
New
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Safe deployments baked into SAM!
Version – immutable deployment unit
Alias – pointer to a version
Lambda Function Foo:
Alias “Live” - Version 5
- Version 6- Version 75%
95%
New
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Safe deployments baked into SAM!
- CodeDeploy integration
- Preconfigured canary and linear deployments
- Auto alarm-based rollbacks
- Pre and post traffic validation hooks
- Monitor through the CodeDeploy console
- Natively supported in SAM!
New
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Safe deployments baked into SAM!
AWSTemplateFormatVersion: '2010-09-09’
Transform: AWS::Serverless-2016-10-31
Resources:
GetHtmlFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://demo-bucket/todo_list.zip
Handler: index.js
Runtime: nodejs6.1
New
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Safe deployments baked into SAM!
AWSTemplateFormatVersion: '2010-09-09’
Transform: AWS::Serverless-2016-10-31
Globals:
Function:
AutoPublishAlias: Live
DeploymentPreference:
Type: Canary10Percent10Minutes
Resources:
GetHtmlFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://demo-bucket/todo_list.zip
Handler: index.js
Runtime: nodejs6.1
Policies: AmazonDynamoDBReadOnlyAccess
New
Safe deployments baked into SAM!
AWSTemplateFormatVersion: '2010-09-09’
Transform: AWS::Serverless-2016-10-31
Globals:
Function:
AutoPublishAlias: Live
DeploymentPreference:
Type: Canary10Percent10Minutes
Hooks:
PreTraffic: !Ref CodeDeployHook_PreTest
PostTraffic: !Ref CodeDeployHook_PostTest
Alarms:
- !Ref DurationAlarm
- !Ref ErrorAlarm
Resources:
GetHtmlFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://demo-bucket/todo_list.zip
Handler: index.js
Runtime: nodejs6.1
Policies: AmazonDynamoDBReadOnlyAccess
New
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Code Deploy console
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Conclusion
Use Lambda console for quick creation and iteration of simple apps
Plug SAM Local into the IDE of your choice for higher fidelity
testing and debugging
“Develop in the cloud” with Cloud9 – optimized for serverless
applications
Build on SAM for CI/CD capabilities, including canary deployments
h t t p s://aw s.am az o n .co m /se r v e r l e ss/de v e l o p e r- t o o ls/
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
THANK YOU!
P l e a s e r e m e m b e r t o r e v i e w t h i s s e s s i o n !
S R V 3 1 1

Contenu connexe

Tendances

Deep Dive on Serverless Application Development
Deep Dive on Serverless Application DevelopmentDeep Dive on Serverless Application Development
Deep Dive on Serverless Application DevelopmentAmazon Web Services
 
What's New in Serverless - SRV305 - re:Invent 2017
What's New in Serverless - SRV305 - re:Invent 2017What's New in Serverless - SRV305 - re:Invent 2017
What's New in Serverless - SRV305 - re:Invent 2017Amazon Web Services
 
Advanced Serverless Apps With Step Functions
Advanced Serverless Apps With Step FunctionsAdvanced Serverless Apps With Step Functions
Advanced Serverless Apps With Step FunctionsAmazon Web Services
 
CON302_Building a CICD Pipeline for Containers on Amazon ECS
CON302_Building a CICD Pipeline for Containers on Amazon ECSCON302_Building a CICD Pipeline for Containers on Amazon ECS
CON302_Building a CICD Pipeline for Containers on Amazon ECSAmazon Web Services
 
Build a Serverless Web Application in One Day
Build a Serverless Web Application in One DayBuild a Serverless Web Application in One Day
Build a Serverless Web Application in One DayAmazon Web Services
 
SRV310_Designing Microservices with Serverless
SRV310_Designing Microservices with ServerlessSRV310_Designing Microservices with Serverless
SRV310_Designing Microservices with ServerlessAmazon Web Services
 
Serverless Architecture Patterns
Serverless Architecture PatternsServerless Architecture Patterns
Serverless Architecture PatternsAmazon Web Services
 
Successfully Migrating Business-Critical Applications to AWS - ENT401 - re:In...
Successfully Migrating Business-Critical Applications to AWS - ENT401 - re:In...Successfully Migrating Business-Critical Applications to AWS - ENT401 - re:In...
Successfully Migrating Business-Critical Applications to AWS - ENT401 - re:In...Amazon Web Services
 
CON209_Interstella 8888 Learn How to Use Docker on AWS
CON209_Interstella 8888 Learn How to Use Docker on AWSCON209_Interstella 8888 Learn How to Use Docker on AWS
CON209_Interstella 8888 Learn How to Use Docker on AWSAmazon Web Services
 
Building CI/CD Pipelines for Serverless Applications - SRV302 - re:Invent 2017
Building CI/CD Pipelines for Serverless Applications - SRV302 - re:Invent 2017Building CI/CD Pipelines for Serverless Applications - SRV302 - re:Invent 2017
Building CI/CD Pipelines for Serverless Applications - SRV302 - re:Invent 2017Amazon Web Services
 
Elastic Load Balancing Deep Dive and Best Practices - NET402 - re:Invent 2017
Elastic Load Balancing Deep Dive and Best Practices - NET402 - re:Invent 2017Elastic Load Balancing Deep Dive and Best Practices - NET402 - re:Invent 2017
Elastic Load Balancing Deep Dive and Best Practices - NET402 - re:Invent 2017Amazon Web Services
 
Keys to Successfully Monitoring and Optimizing Innovative and Sophisticated C...
Keys to Successfully Monitoring and Optimizing Innovative and Sophisticated C...Keys to Successfully Monitoring and Optimizing Innovative and Sophisticated C...
Keys to Successfully Monitoring and Optimizing Innovative and Sophisticated C...Amazon Web Services
 
Advanced Container Management and Scheduling
Advanced Container Management and SchedulingAdvanced Container Management and Scheduling
Advanced Container Management and SchedulingAmazon Web Services
 
Deep Dive on Serverless Application Development
Deep Dive on Serverless Application DevelopmentDeep Dive on Serverless Application Development
Deep Dive on Serverless Application DevelopmentAmazon Web Services
 
Serverless Architectural Patterns
Serverless Architectural PatternsServerless Architectural Patterns
Serverless Architectural PatternsAmazon Web Services
 
DEV328_DevOps Lessons from Courser a Site Performance, Reliability, and Devel...
DEV328_DevOps Lessons from Courser a Site Performance, Reliability, and Devel...DEV328_DevOps Lessons from Courser a Site Performance, Reliability, and Devel...
DEV328_DevOps Lessons from Courser a Site Performance, Reliability, and Devel...Amazon Web Services
 

Tendances (20)

Deep Dive on Serverless Application Development
Deep Dive on Serverless Application DevelopmentDeep Dive on Serverless Application Development
Deep Dive on Serverless Application Development
 
AI: State of the Union
AI: State of the UnionAI: State of the Union
AI: State of the Union
 
What's New in Serverless - SRV305 - re:Invent 2017
What's New in Serverless - SRV305 - re:Invent 2017What's New in Serverless - SRV305 - re:Invent 2017
What's New in Serverless - SRV305 - re:Invent 2017
 
Advanced Serverless Apps With Step Functions
Advanced Serverless Apps With Step FunctionsAdvanced Serverless Apps With Step Functions
Advanced Serverless Apps With Step Functions
 
CON302_Building a CICD Pipeline for Containers on Amazon ECS
CON302_Building a CICD Pipeline for Containers on Amazon ECSCON302_Building a CICD Pipeline for Containers on Amazon ECS
CON302_Building a CICD Pipeline for Containers on Amazon ECS
 
Build a Serverless Web Application in One Day
Build a Serverless Web Application in One DayBuild a Serverless Web Application in One Day
Build a Serverless Web Application in One Day
 
SRV310_Designing Microservices with Serverless
SRV310_Designing Microservices with ServerlessSRV310_Designing Microservices with Serverless
SRV310_Designing Microservices with Serverless
 
Serverless Architecture Patterns
Serverless Architecture PatternsServerless Architecture Patterns
Serverless Architecture Patterns
 
Successfully Migrating Business-Critical Applications to AWS - ENT401 - re:In...
Successfully Migrating Business-Critical Applications to AWS - ENT401 - re:In...Successfully Migrating Business-Critical Applications to AWS - ENT401 - re:In...
Successfully Migrating Business-Critical Applications to AWS - ENT401 - re:In...
 
Introducing Amazon EKS
Introducing Amazon EKSIntroducing Amazon EKS
Introducing Amazon EKS
 
CON209_Interstella 8888 Learn How to Use Docker on AWS
CON209_Interstella 8888 Learn How to Use Docker on AWSCON209_Interstella 8888 Learn How to Use Docker on AWS
CON209_Interstella 8888 Learn How to Use Docker on AWS
 
Building CI/CD Pipelines for Serverless Applications - SRV302 - re:Invent 2017
Building CI/CD Pipelines for Serverless Applications - SRV302 - re:Invent 2017Building CI/CD Pipelines for Serverless Applications - SRV302 - re:Invent 2017
Building CI/CD Pipelines for Serverless Applications - SRV302 - re:Invent 2017
 
Elastic Load Balancing Deep Dive and Best Practices - NET402 - re:Invent 2017
Elastic Load Balancing Deep Dive and Best Practices - NET402 - re:Invent 2017Elastic Load Balancing Deep Dive and Best Practices - NET402 - re:Invent 2017
Elastic Load Balancing Deep Dive and Best Practices - NET402 - re:Invent 2017
 
Keys to Successfully Monitoring and Optimizing Innovative and Sophisticated C...
Keys to Successfully Monitoring and Optimizing Innovative and Sophisticated C...Keys to Successfully Monitoring and Optimizing Innovative and Sophisticated C...
Keys to Successfully Monitoring and Optimizing Innovative and Sophisticated C...
 
Advanced Container Management and Scheduling
Advanced Container Management and SchedulingAdvanced Container Management and Scheduling
Advanced Container Management and Scheduling
 
Serverless Developer Experience
Serverless Developer ExperienceServerless Developer Experience
Serverless Developer Experience
 
Deep Dive on Serverless Application Development
Deep Dive on Serverless Application DevelopmentDeep Dive on Serverless Application Development
Deep Dive on Serverless Application Development
 
Introducing AWS Fargate
Introducing AWS FargateIntroducing AWS Fargate
Introducing AWS Fargate
 
Serverless Architectural Patterns
Serverless Architectural PatternsServerless Architectural Patterns
Serverless Architectural Patterns
 
DEV328_DevOps Lessons from Courser a Site Performance, Reliability, and Devel...
DEV328_DevOps Lessons from Courser a Site Performance, Reliability, and Devel...DEV328_DevOps Lessons from Courser a Site Performance, Reliability, and Devel...
DEV328_DevOps Lessons from Courser a Site Performance, Reliability, and Devel...
 

Similaire à Authoring and Deploying Serverless Applications with AWS SAM - SRV311 - re:Invent 2017

SRV331_Build a Multi-Region Serverless Application for Resilience and High Av...
SRV331_Build a Multi-Region Serverless Application for Resilience and High Av...SRV331_Build a Multi-Region Serverless Application for Resilience and High Av...
SRV331_Build a Multi-Region Serverless Application for Resilience and High Av...Amazon Web Services
 
Serverless Developer Experience I AWS Dev Day 2018
Serverless Developer Experience I AWS Dev Day 2018Serverless Developer Experience I AWS Dev Day 2018
Serverless Developer Experience I AWS Dev Day 2018AWS Germany
 
High-Throughput Genomics on AWS - LFS309 - re:Invent 2017
High-Throughput Genomics on AWS - LFS309 - re:Invent 2017High-Throughput Genomics on AWS - LFS309 - re:Invent 2017
High-Throughput Genomics on AWS - LFS309 - re:Invent 2017Amazon Web Services
 
LFS309-High-Throughput Genomics on AWS.pdf
LFS309-High-Throughput Genomics on AWS.pdfLFS309-High-Throughput Genomics on AWS.pdf
LFS309-High-Throughput Genomics on AWS.pdfAmazon Web Services
 
CI/CD for AWS Lambda Projects - IsraelCloud Meetup
CI/CD for AWS Lambda Projects - IsraelCloud MeetupCI/CD for AWS Lambda Projects - IsraelCloud Meetup
CI/CD for AWS Lambda Projects - IsraelCloud MeetupBoaz Ziniman
 
Application Performance Management on AWS - ARC317 - re:Invent 2017
Application Performance Management on AWS - ARC317 - re:Invent 2017Application Performance Management on AWS - ARC317 - re:Invent 2017
Application Performance Management on AWS - ARC317 - re:Invent 2017Amazon Web Services
 
Use Amazon EC2 Systems Manager to Perform Automated Resilience Testing in You...
Use Amazon EC2 Systems Manager to Perform Automated Resilience Testing in You...Use Amazon EC2 Systems Manager to Perform Automated Resilience Testing in You...
Use Amazon EC2 Systems Manager to Perform Automated Resilience Testing in You...Amazon Web Services
 
Deep Dive on Serverless App Development
Deep Dive on Serverless App DevelopmentDeep Dive on Serverless App Development
Deep Dive on Serverless App DevelopmentAmazon Web Services
 
Deep Dive On Serverless App Development
Deep Dive On Serverless App DevelopmentDeep Dive On Serverless App Development
Deep Dive On Serverless App DevelopmentAmazon Web Services
 
ABD215_Serverless Data Prep with AWS Glue
ABD215_Serverless Data Prep with AWS GlueABD215_Serverless Data Prep with AWS Glue
ABD215_Serverless Data Prep with AWS GlueAmazon Web Services
 
ABD215_Serverless Data Prep with AWS Glue
ABD215_Serverless Data Prep with AWS GlueABD215_Serverless Data Prep with AWS Glue
ABD215_Serverless Data Prep with AWS GlueAmazon Web Services
 
Serverless-AWS SAM CLI Session: Developer Meet Up
Serverless-AWS SAM CLI Session: Developer Meet UpServerless-AWS SAM CLI Session: Developer Meet Up
Serverless-AWS SAM CLI Session: Developer Meet UpAmazon Web Services
 
AWS X-Ray: Debugging Applications at Scale - AWS Online Tech Talks
AWS X-Ray: Debugging Applications at Scale - AWS Online Tech TalksAWS X-Ray: Debugging Applications at Scale - AWS Online Tech Talks
AWS X-Ray: Debugging Applications at Scale - AWS Online Tech TalksAmazon Web Services
 
Become a Serverless Black Belt: Optimizing Your Serverless Applications - SRV...
Become a Serverless Black Belt: Optimizing Your Serverless Applications - SRV...Become a Serverless Black Belt: Optimizing Your Serverless Applications - SRV...
Become a Serverless Black Belt: Optimizing Your Serverless Applications - SRV...Amazon Web Services
 
Application Performance Management on AWS
Application Performance Management on AWSApplication Performance Management on AWS
Application Performance Management on AWSAmazon Web Services
 
Ci/CD for AWS Lambda Projects - JLM CTO Club
Ci/CD for AWS Lambda Projects - JLM CTO ClubCi/CD for AWS Lambda Projects - JLM CTO Club
Ci/CD for AWS Lambda Projects - JLM CTO ClubBoaz Ziniman
 

Similaire à Authoring and Deploying Serverless Applications with AWS SAM - SRV311 - re:Invent 2017 (20)

SRV331_Build a Multi-Region Serverless Application for Resilience and High Av...
SRV331_Build a Multi-Region Serverless Application for Resilience and High Av...SRV331_Build a Multi-Region Serverless Application for Resilience and High Av...
SRV331_Build a Multi-Region Serverless Application for Resilience and High Av...
 
Serverless Developer Experience I AWS Dev Day 2018
Serverless Developer Experience I AWS Dev Day 2018Serverless Developer Experience I AWS Dev Day 2018
Serverless Developer Experience I AWS Dev Day 2018
 
Meet AWS SAM
Meet AWS SAMMeet AWS SAM
Meet AWS SAM
 
High-Throughput Genomics on AWS - LFS309 - re:Invent 2017
High-Throughput Genomics on AWS - LFS309 - re:Invent 2017High-Throughput Genomics on AWS - LFS309 - re:Invent 2017
High-Throughput Genomics on AWS - LFS309 - re:Invent 2017
 
LFS309-High-Throughput Genomics on AWS.pdf
LFS309-High-Throughput Genomics on AWS.pdfLFS309-High-Throughput Genomics on AWS.pdf
LFS309-High-Throughput Genomics on AWS.pdf
 
CI/CD for AWS Lambda Projects - IsraelCloud Meetup
CI/CD for AWS Lambda Projects - IsraelCloud MeetupCI/CD for AWS Lambda Projects - IsraelCloud Meetup
CI/CD for AWS Lambda Projects - IsraelCloud Meetup
 
Application Performance Management on AWS - ARC317 - re:Invent 2017
Application Performance Management on AWS - ARC317 - re:Invent 2017Application Performance Management on AWS - ARC317 - re:Invent 2017
Application Performance Management on AWS - ARC317 - re:Invent 2017
 
Use Amazon EC2 Systems Manager to Perform Automated Resilience Testing in You...
Use Amazon EC2 Systems Manager to Perform Automated Resilience Testing in You...Use Amazon EC2 Systems Manager to Perform Automated Resilience Testing in You...
Use Amazon EC2 Systems Manager to Perform Automated Resilience Testing in You...
 
Deep Dive on Serverless App Development
Deep Dive on Serverless App DevelopmentDeep Dive on Serverless App Development
Deep Dive on Serverless App Development
 
Deep Dive On Serverless App Development
Deep Dive On Serverless App DevelopmentDeep Dive On Serverless App Development
Deep Dive On Serverless App Development
 
ABD215_Serverless Data Prep with AWS Glue
ABD215_Serverless Data Prep with AWS GlueABD215_Serverless Data Prep with AWS Glue
ABD215_Serverless Data Prep with AWS Glue
 
ABD215_Serverless Data Prep with AWS Glue
ABD215_Serverless Data Prep with AWS GlueABD215_Serverless Data Prep with AWS Glue
ABD215_Serverless Data Prep with AWS Glue
 
Serverless-AWS SAM CLI Session: Developer Meet Up
Serverless-AWS SAM CLI Session: Developer Meet UpServerless-AWS SAM CLI Session: Developer Meet Up
Serverless-AWS SAM CLI Session: Developer Meet Up
 
AWS X-Ray: Debugging Applications at Scale - AWS Online Tech Talks
AWS X-Ray: Debugging Applications at Scale - AWS Online Tech TalksAWS X-Ray: Debugging Applications at Scale - AWS Online Tech Talks
AWS X-Ray: Debugging Applications at Scale - AWS Online Tech Talks
 
Serverless Functions Deep Dive
Serverless Functions Deep DiveServerless Functions Deep Dive
Serverless Functions Deep Dive
 
Become a Serverless Black Belt: Optimizing Your Serverless Applications - SRV...
Become a Serverless Black Belt: Optimizing Your Serverless Applications - SRV...Become a Serverless Black Belt: Optimizing Your Serverless Applications - SRV...
Become a Serverless Black Belt: Optimizing Your Serverless Applications - SRV...
 
Devops on serverless
Devops on serverlessDevops on serverless
Devops on serverless
 
Serverless functions deep dive
Serverless functions deep diveServerless functions deep dive
Serverless functions deep dive
 
Application Performance Management on AWS
Application Performance Management on AWSApplication Performance Management on AWS
Application Performance Management on AWS
 
Ci/CD for AWS Lambda Projects - JLM CTO Club
Ci/CD for AWS Lambda Projects - JLM CTO ClubCi/CD for AWS Lambda Projects - JLM CTO Club
Ci/CD for AWS Lambda Projects - JLM CTO Club
 

Plus de Amazon Web Services

Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...Amazon Web Services
 
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...Amazon Web Services
 
Esegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS FargateEsegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS FargateAmazon Web Services
 
Costruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWSCostruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWSAmazon Web Services
 
Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot Amazon Web Services
 
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...Amazon Web Services
 
OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...Amazon Web Services
 
Microsoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows WorkloadsMicrosoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows WorkloadsAmazon Web Services
 
Database Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatareDatabase Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatareAmazon Web Services
 
Crea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJSCrea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJSAmazon Web Services
 
API moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e webAPI moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e webAmazon Web Services
 
Database Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatareDatabase Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatareAmazon Web Services
 
Tools for building your MVP on AWS
Tools for building your MVP on AWSTools for building your MVP on AWS
Tools for building your MVP on AWSAmazon Web Services
 
How to Build a Winning Pitch Deck
How to Build a Winning Pitch DeckHow to Build a Winning Pitch Deck
How to Build a Winning Pitch DeckAmazon Web Services
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without serversAmazon Web Services
 
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...Amazon Web Services
 
Introduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container ServiceIntroduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container ServiceAmazon Web Services
 

Plus de Amazon Web Services (20)

Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
 
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
 
Esegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS FargateEsegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS Fargate
 
Costruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWSCostruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWS
 
Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot
 
Open banking as a service
Open banking as a serviceOpen banking as a service
Open banking as a service
 
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
 
OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...
 
Microsoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows WorkloadsMicrosoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows Workloads
 
Computer Vision con AWS
Computer Vision con AWSComputer Vision con AWS
Computer Vision con AWS
 
Database Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatareDatabase Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatare
 
Crea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJSCrea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJS
 
API moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e webAPI moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e web
 
Database Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatareDatabase Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatare
 
Tools for building your MVP on AWS
Tools for building your MVP on AWSTools for building your MVP on AWS
Tools for building your MVP on AWS
 
How to Build a Winning Pitch Deck
How to Build a Winning Pitch DeckHow to Build a Winning Pitch Deck
How to Build a Winning Pitch Deck
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without servers
 
Fundraising Essentials
Fundraising EssentialsFundraising Essentials
Fundraising Essentials
 
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
 
Introduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container ServiceIntroduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container Service
 

Authoring and Deploying Serverless Applications with AWS SAM - SRV311 - re:Invent 2017

  • 1. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS re:INVENT Authoring and Deploying Serverless Applications with AWS SAM O r r W e i n s t e i n – S r . P r o d u c t M a n a g e r – A W S L a m b d a S R V 3 1 1 D e c e m b e r 1 , 2 0 1 7
  • 2. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Agenda - Intro - Dev iteration loop - Author (application and code) - Test - Debug - Serverless Deployments
  • 3. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Serverless applications ANYTHING Changes in data state Requests to endpoints Changes in resource state EVENT SOURCE FUNCTION Node.js Python Java C# Go – Coming soon!
  • 4. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Serverless means… No servers to provision or manage Scales with usage Never pay for idle Availability and fault tolerance built in
  • 6. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Running for over 18 months, at 4,000+ requests per second Low latency processing No action required to handle fluctuations in scale
  • 7. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. ALM for serverless applications Author Build Test DeployDebugTest CI/CD Source Author/test/debug
  • 8. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Author/test/debug Author Test Debug Simple app No team members No code repo What if:
  • 9. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. New and improved Lambda console Cloud9 editor within the Lambda console Function graph Persisted test events Monitoring view (jump to logs for any timeframe) New
  • 10. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Demo #1: Author, test and debug in the Lambda console
  • 11. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Tips - Lambda console editor - Useful keyboard shortcuts - Full screen Cmd + Shift + F - Cache file locally Cmd + S - Save (UpdateFunctionCode) Cmd + Shft + U - Test Cmd + I - Configure test events Cmd + J
  • 12. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Author/Test/Debug cycle Author C o d e A p p l i c a t i o n Test Debug
  • 14. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Serverless Application Model (SAM) CloudFormation extension optimized for serverless New serverless resource types: functions, APIs, and tables Supports anything CloudFormation supports Open specification (Apache 2.0)
  • 15. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. CloudFormation Provision and manage a collection of related AWS resources. Your application = CloudFormation stack Input .yaml file and output provisioned AWS resources
  • 16. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWSTemplateFormatVersion: '2010-09-09’ Transform: AWS::Serverless-2016-10-31 Resources: GetHtmlFunction: Type: AWS::Serverless::Function Properties: CodeUri: s3://demo-bucket/todo_list.zip Handler: index.js Runtime: nodejs6.1 Policies: AmazonDynamoDBReadOnlyAccess Events: GetHtml: Type: Api Properties: Path: /{proxy+} Method: ANY SAM template
  • 17. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWSTemplateFormatVersion: '2010-09-09’ Transform: AWS::Serverless-2016-10-31 Resources: GetHtmlFunction: Type: AWS::Serverless::Function Properties: CodeUri: s3://demo-bucket/todo_list.zip Handler: index.js Runtime: nodejs6.1 Policies: AmazonDynamoDBReadOnlyAccess Events: GetHtml: Type: Api Properties: Path: /{proxy+} Method: ANY SAM template AWS::Lambda::Function AWS::IAM::Role AWS::IAM::Policy AWS::ApiGateway::RestApi AWS::ApiGateway::Stage AWS::ApiGateway::Deployment AWS::Lambda::Permission
  • 18. CloudFormation template AWSTemplateFormatVersion: '2010-09-09' Resources: GetHtmlFunctionGetHtmlPermissionProd: Type: AWS::Lambda::Permission Properties: Action: lambda:invokeFunction Principal: apigateway.amazonaws.com FunctionName: Ref: GetHtmlFunction SourceArn: Fn::Sub: arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${ServerlessRestApi}/Prod/ANY/* ServerlessRestApiProdStage: Type: AWS::ApiGateway::Stage Properties: DeploymentId: Ref: ServerlessRestApiDeployment RestApiId: Ref: ServerlessRestApi StageName: Prod ListTable: Type: AWS::DynamoDB::Table Properties: ProvisionedThroughput: WriteCapacityUnits: 5 ReadCapacityUnits: 5 AttributeDefinitions: - AttributeName: id AttributeType: S KeySchema: - KeyType: HASH AttributeName: id GetHtmlFunction: Type: AWS::Lambda::Function Properties: Handler: index.gethtml Code: S3Bucket: flourish-demo-bucket S3Key: todo_list.zip Role: Fn::GetAtt: - GetHtmlFunctionRole - Arn Runtime: nodejs4.3 GetHtmlFunctionRole: Type: AWS::IAM::Role ManagedPolicyArns: - arn:aws:iam::aws:policy/AmazonDynamoDBReadOnlyAccess - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole AssumeRolePolicyDocument: Version: '2012-10-17' Statement: - Action: - sts:AssumeRole Effect: Allow Principal: Service: - lambda.amazonaws.com ServerlessRestApiDeployment: Type: AWS::ApiGateway::Deployment Properties: RestApiId: Ref: ServerlessRestApi Description: 'RestApi deployment id: 127e3fb91142ab1ddc5f5446adb094442581a90d' StageName: Stage GetHtmlFunctionGetHtmlPermissionTest: Type: AWS::Lambda::Permission Properties: Action: lambda:invokeFunction Principal: apigateway.amazonaws.com FunctionName: Ref: GetHtmlFunction SourceArn: Fn::Sub: arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${ServerlessRestApi}/*/ANY/* ServerlessRestApi: Type: AWS::ApiGateway::RestApi Properties: Body: info: version: '1.0' title: Ref: AWS::StackName paths: "/{proxy+}": x-amazon-apigateway-any-method: x-amazon-apigateway-integration: httpMethod: ANY type: aws_proxy uri: Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03- 31/functions/${GetHtmlFunction.Arn}/invocations
  • 19. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Author C o d eA p p l i c a t i o n Author/Test/Debug cycle
  • 20. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS Cloud9 Cloud-based dev environment Write, test and debug with just a browser Optimized for serverless New
  • 21. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. C o d eA p p l i c a t i o n Test Debug Author/Test/Debug cycle Wait, what about test and debug? Author
  • 22. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Testing serverless apps - challenges - Test in an environment that resembles Lambda: - OS - Libraries - Runtime - Configured limits (memory, timeout) - Mimic response and log outputs
  • 23. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Testing serverless apps - challenges - Test events need to be: - Syntactically accurate - Different for each trigger
  • 24. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Testing serverless apps - challenges { "Records": [ { "eventVersion": "2.0", "eventTime": "1970-01-01T00:00:00.000Z", "requestParameters": { "sourceIPAddress": "127.0.0.1" }, "s3": { "configurationId": "testConfigRule", "object": { "eTag": "0123456789abcdef0123456789abcdef", "sequencer": "0A1B2C3D4E5F678901", "key": "myKey", "size": 1024 }, "bucket": { "arn": "arn:aws:s3:::myBucket", "name": "myBucket", "ownerIdentity": { "principalId": "EXAMPLE" } }, "s3SchemaVersion": "1.0" }, "responseElements": { "x-amz-id-2": "EXAMPLE123/5678abcdefghijklambdaisawesome/mnop qrstuvwxyzABCDEFGH", "x-amz-request-id": "EXAMPLE123456789" }, "awsRegion": "us-east-1", "eventName": "ObjectCreated:Put", "userIdentity": { "principalId": "EXAMPLE" }, "eventSource": "aws:s3” } ] }
  • 25. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Introducing SAM Local CLI tool for local testing of serverless apps Leverages Docker images to mimic Lambda’s execution environment Emulates Lambda functions and APIs Event generator to help you generate event payload for common Lambda triggers sam local generate-event s3 --bucket <bucket> --key <key>
  • 26. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Introducing SAM Local Response object and function logs available on your local machine Supports live debugging Currently supports Java, Node.js and Python SAM Local is open source & accepting pull requests! https://github.com/awslabs/aws-sam-local npm install –g aws-sam-local
  • 27. $ sam --help NAME: sam - ___ _____ ___ _ __ __ /_ / / __| / __| /_ | / | / _ // /__ __ / _ | |/| | /_/ __/_/ |___/ |___/_/ __| |_| AWS Serverless Application Model (SAM) CLI The AWS Serverless Application Model extends AWS CloudFormation to provide a simplified way of defining the Amazon API Gateway APIs, AWS Lambda functions, and Amazon DynamoDB tables needed by your serverless application. You can find more in-depth guide about the SAM specification here:nhttps://github.com/awslabs/serverless-application-model. USAGE: sam [global options] command [command options] [arguments...] VERSION: 0.2.0 COMMANDS: local Run your Serverless application locally for quick development & testing validate Validates an AWS SAM template. If valid, will print a summary of the resources found within the SAM template. If the template is invalid, returns a non-zero exit code. package Package an AWS SAM application. This is an alias for 'aws cloudformation package'. deploy Deploy an AWS SAM application. This is an alias for 'aws cloudformation deploy'. help, h Shows a list of commands or help for one command GLOBAL OPTIONS: --help, -h show help --version, -v print the version
  • 28. $ sam local --help .. USAGE: sam local command [command options] [arguments...] COMMANDS: start-api Allows you to run your Serverless application locally for quick development & testing. When run in a directory that contains your Serverless functions and your AWS SAM template, it will create a local HTTP server hosting all of your functions. When accessed (via browser, cli etc), it will launch a Docker container locally to invoke the function. It will read the CodeUri property of AWS::Serverless::Function resource to find the path in your file system containing the Lambda Function code. This could be the project's root directory for interpreted languages like Node & Python, or a build directory that stores your compiled artifacts or a JAR file. If you are using a interpreted language, local changes will be available immediately in Docker container on every invoke. For more compiled languages or projects requiring complex packing support, we recommended you run your own building solution and point SAM to the directory or file containing build artifacts. invoke Invokes a local Lambda function once and quits after invocation completes. Useful for developing serverless functions that handle asynchronous events (such as S3/Kinesis etc), or if you want to compose a script of test cases. Event body can be passed in either by stdin (default), or by using the --event parameter. Runtime output (logs etc) will be outputted to stderr, and the Lambda function result will be outputted to stdout. generate-event Generates Lambda events (e.g. for S3/Kinesis etc) that can be piped to 'sam local invoke'
  • 29. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Demo #2: Author, test & debug in AWS Cloud9
  • 30. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Author C o d eA p p l i c a t i o n Test Debug Author/Test/Debug cycle
  • 31. </> GitHub Amazon S3 AWS CodeCommit AWS CodeBuild AWS CodeBuild Third-party tools AWS CloudFormation Source Build Test Deploy Deploying serverless applications
  • 32. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Safe deployments baked into SAM! Lambda aliases now enable traffic shifting CodeDeploy integration for deployment automation Deployment automation natively supported in SAM New
  • 33. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Safe deployments baked into SAM! Version – immutable deployment unit Alias – pointer to a version Lambda Function Foo: Alias “Live” - Version 5 - Version 6- Version 75% 95% New
  • 34. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Safe deployments baked into SAM! - CodeDeploy integration - Preconfigured canary and linear deployments - Auto alarm-based rollbacks - Pre and post traffic validation hooks - Monitor through the CodeDeploy console - Natively supported in SAM! New
  • 35. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Safe deployments baked into SAM! AWSTemplateFormatVersion: '2010-09-09’ Transform: AWS::Serverless-2016-10-31 Resources: GetHtmlFunction: Type: AWS::Serverless::Function Properties: CodeUri: s3://demo-bucket/todo_list.zip Handler: index.js Runtime: nodejs6.1 New
  • 36. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Safe deployments baked into SAM! AWSTemplateFormatVersion: '2010-09-09’ Transform: AWS::Serverless-2016-10-31 Globals: Function: AutoPublishAlias: Live DeploymentPreference: Type: Canary10Percent10Minutes Resources: GetHtmlFunction: Type: AWS::Serverless::Function Properties: CodeUri: s3://demo-bucket/todo_list.zip Handler: index.js Runtime: nodejs6.1 Policies: AmazonDynamoDBReadOnlyAccess New
  • 37. Safe deployments baked into SAM! AWSTemplateFormatVersion: '2010-09-09’ Transform: AWS::Serverless-2016-10-31 Globals: Function: AutoPublishAlias: Live DeploymentPreference: Type: Canary10Percent10Minutes Hooks: PreTraffic: !Ref CodeDeployHook_PreTest PostTraffic: !Ref CodeDeployHook_PostTest Alarms: - !Ref DurationAlarm - !Ref ErrorAlarm Resources: GetHtmlFunction: Type: AWS::Serverless::Function Properties: CodeUri: s3://demo-bucket/todo_list.zip Handler: index.js Runtime: nodejs6.1 Policies: AmazonDynamoDBReadOnlyAccess New
  • 38. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Code Deploy console
  • 39. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Conclusion Use Lambda console for quick creation and iteration of simple apps Plug SAM Local into the IDE of your choice for higher fidelity testing and debugging “Develop in the cloud” with Cloud9 – optimized for serverless applications Build on SAM for CI/CD capabilities, including canary deployments
  • 40. h t t p s://aw s.am az o n .co m /se r v e r l e ss/de v e l o p e r- t o o ls/
  • 41. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. THANK YOU! P l e a s e r e m e m b e r t o r e v i e w t h i s s e s s i o n ! S R V 3 1 1