SlideShare a Scribd company logo
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Boaz Ziniman - Technical Evangelist
Amazon Web Service
Serverless Beyond Functions
@ziniman
boaz.ziniman.aws
ziniman
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Serverless applications
Services (anything)
Changes in
data state
Requests to
endpoints
Changes in
resource state
Event source Function
Node.js
Python
Java
C# / F# / PowerShell
Go
Ruby
Runtime API
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Anatomy of a Lambda function
Handler() function
Function to be executed
upon invocation
Event object
Data sent during Lambda
function Invocation
Context object
Methods available to
interact with runtime
information (request ID,
log group, more)
import json
def lambda_handler(event, context):
# TODO implement
return {
'statusCode': 200,
'body': json.dumps('Hello World!')
}
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
“I know how to build a serverless
function, now what?”
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Agenda
• Orchestration
• CI/CD
• Step Functions
• Layers
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Project Orchestration
© 2019, Amazon Web Services, Inc. or its Affiliates.
Start with a framework
AWS
Chalice
AWS Amplify
AWS
SAM
AWS: Third-party:
Serverless
Framework
Meet
SAM!
© 2019, Amazon Web Services, Inc. or its Affiliates.
AWS Serverless Application Model (SAM)
AWS CloudFormation extension optimized for
serverless
Special serverless resource types: Functions, APIs,
SimpleTables, Layers, and Applications
Supports anything AWS CloudFormation supports
Open specification (Apache 2.0)
https://aws.amazon.com/serverless/sam
© 2019, Amazon Web Services, Inc. or its Affiliates.
AWS Serverless Application Model (SAM)
AWSTemplateFormatVersion: '2010-09-09’
Transform: AWS::Serverless-2016-10-31
Resources:
GetFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.get
Runtime: nodejs8.10
CodeUri: src/
Policies:
- DynamoDBReadPolicy:
TableName: !Ref MyTable
Events:
GetResource:
Type: Api
Properties:
Path: /resource/{resourceId}
Method: get
MyTable:
Type: AWS::Serverless::SimpleTable
Just 20 lines to create:
• Lambda function
• IAM role
• API Gateway
• DynamoDB table
O
pen
Source
© 2019, Amazon Web Services, Inc. or its Affiliates.
Use SAM CLI to package and deploy SAM templates
pip install --user aws-sam-cli
sam init --name my-app --runtime python
cd my-app/
sam local ... # generate-event/invoke/start-api/start-lambda
sam validate # The SAM template
sam build # Depending on the runtime
sam package --s3-bucket my-packages-bucket 
--output-template-file packaged.yaml
sam deploy --template-file packaged.yaml 
--stack-name my-stack-prod
sam logs -n MyFunction --stack-name my-stack-prod -t # Tail
sam publish # To the Serverless Application Repository
O
pen
Source
CodePipeline
Use
CloudFormation
deployment actions
with any SAM
application
Jenkins
Use SAM CLI plugin
© 2019, Amazon Web Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates.
© 2019, Amazon Web Services, Inc. or its Affiliates.
With the AWS Serverless Application Repository:
Developers can…
• Discover and deploy ready-made apps and
code samples
• Combine applications in the app repository
with their own via Nested Applications
• Customize open-source apps to get started
quickly
• Share apps privately or publish apps
for public use
© 2019, Amazon Web Services, Inc. or its Affiliates.
TweetSource:
Type: AWS::Serverless::Application
Properties:
Location:
ApplicationId: arn:aws:serverlessrepo:...
SemanticVersion: 2.0.0
Parameters:
TweetProcessorFunctionName: !Ref MyFunction
SearchText: '#serverless -filter:nativeretweets'
Nested apps to simplify solving recurring problems
Standard
Component
Custom
Business
Logic
Polling schedule
(CloudWatch
Events rule)
trigger
TwitterProcessor
SearchCheckpoint
TwitterSearchPoller
Twitter
Search API
© 2019, Amazon Web Services, Inc. or its Affiliates.
AWS Lambda Environment Variables
• Key-value pairs that you can dynamically pass to your
function
• Available via standard environment variable APIs such
as process.env for Node.js or os.environ for Python
• Can optionally be encrypted via AWS Key
Management Service (KMS)
• Allows you to specify in IAM what roles have access to the
keys to decrypt the information
• Useful for creating environments per stage
(i.e. dev, testing, production)
© 2019, Amazon Web Services, Inc. or its Affiliates.
Amazon API Gateway Stage Variables
Stage variables act like environment variables
• Use stage variables to store configuration values
• Stage variables are available in the $context object
• Values are accessible from most fields
in API Gateway
• Lambda function ARN
• HTTP endpoint
• Custom authorizer function name
• Parameter mappings
Amazon API
Gateway
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
CI/CD for Serverless
© 2019, Amazon Web Services, Inc. or its Affiliates.
Source Build Test Production
Continuous Integration / Continuous Deployment
© 2019, Amazon Web Services, Inc. or its Affiliates.
Serverless deployments
Code
StackPackage Deploy
Template
© 2019, Amazon Web Services, Inc. or its Affiliates.
Serverless deployments with a test environment
Code
Test
Stack
Package Deploy
Template
Feedback
Production
Stack
Deploy
© 2019, Amazon Web Services, Inc. or its Affiliates.
MyLambdaFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs6.10
AutoPublishAlias: !Ref ENVIRONMENT
DeploymentPreference:
Type: Linear10PercentEvery10Minutes
Alarms:
# A list of alarms that you want to monitor
- !Ref AliasErrorMetricGreaterThanZeroAlarm
- !Ref LatestVersionErrorMetricGreaterThanZeroAlarm
Hooks:
# Validation Lambda functions that are run before & after traffic shifting
PreTraffic: !Ref PreTrafficLambdaFunction
PostTraffic: !Ref PostTrafficLambdaFunction
AWS SAM + Safe Deployments
© 2019, Amazon Web Services, Inc. or its Affiliates.
CodeDeploy – Lambda deployments in SAM templates
Resources:
GetFunction:
Type: AWS::Serverless::Function
Properties:
AutoPublishAlias: live
DeploymentPreference:
Type: Canary10Percent10Minutes
Alarms:
- !Ref ErrorsAlarm
- !Ref LatencyAlarm
Hooks:
PreTraffic: !Ref PreTrafficHookFunction
PostTraffic: !Ref PostTrafficHookFunction
Canary10Percent30Minutes
Canary10Percent5Minutes
Canary10Percent10Minutes
Canary10Percent15Minutes
Linear10PercentEvery10Minutes
Linear10PercentEvery1Minute
Linear10PercentEvery2Minutes
Linear10PercentEvery3Minutes
AllAtOnce
© 2019, Amazon Web Services, Inc. or its Affiliates.
Alarms: # A list of alarms that you want to monitor
- !Ref AliasErrorMetricGreaterThanZeroAlarm
- !Ref LatestVersionErrorMetricGreaterThanZeroAlarm
Hooks: # Validation Lambda functions that are run before & after
traffic shifting
PreTraffic: !Ref PreTrafficLambdaFunction
PostTraffic: !Ref PostTrafficLambdaFunction
AWS Lambda Alias Traffic Shifting & AWS SAM
Note: You can specify a maximum of 10
alarms
In SAM:
© 2019, Amazon Web Services, Inc. or its Affiliates.
CodeDeploy – Lambda canary deployment
API
Gateway
Lambda
function
weighted
alias
“live”
v1
Lambda
function
code
100%
© 2019, Amazon Web Services, Inc. or its Affiliates.
CodeDeploy – Lambda canary deployment
API
Gateway
Lambda
function
weighted
alias
“live”
v1 code100%
Run PreTraffic hook against v2 code before it receives traffic
v2 code0%
© 2019, Amazon Web Services, Inc. or its Affiliates.
CodeDeploy – Lambda canary deployment
API
Gateway
Lambda
function
weighted
alias
“live”
v1 code90%
Wait for 10 minutes, roll back in case of alarm
v2 code10%
© 2019, Amazon Web Services, Inc. or its Affiliates.
CodeDeploy – Lambda canary deployment
API
Gateway
Lambda
function
weighted
alias
“live”
v1 code0%
Run PostTraffic hook and complete deployment
v2 code100%
© 2019, Amazon Web Services, Inc. or its Affiliates.
API Gateway canary stage
API
Gateway
Production
stage
v1 code
v2 code
99.5%
0.5% Canary
stage
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Demo
https://github.com/ziniman/aws-devday-storereply
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Step Functions
Application Lifecycle in AWS Step Functions
Visualize in the
Console
Define in JSON Monitor
Executions
Define in JSON and Then Visualize in the Console
{
"Comment": "Hello World Example",
"StartAt" : "HelloWorld",
"States" : {
"HelloWorld" : {
"Type" : "Task",
"Resource" : "${lambdaArn}",
"End" : true
}
}
}
Execute One or One Million
Start
End
HelloWorld
Start
End
HelloWorld
Start
End
HelloWorld
Start
End
HelloWorld
Start
End
HelloWorld
Start
End
HelloWorld
Start
End
HelloWorld
Start
End
HelloWorld
Maximum Execution Time
AWS Lambda
Functions
15 minutes
AWS Step Functions
State Machines
1 year
Monitor Executions from the Console
Seven State Types
Task A single unit of work
Choice Adds branching logic
Parallel Fork and join the data across tasks
Wait Delay for a specified time
Fail Stops an execution and marks it as a failure
Succeed Stops an execution successfully
Pass Passes its input to its output
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Step Functions Tasks – Service Integrations
AWS Lambda invoke a Lambda function
AWS Batch submit a Batch job and wait for it to complete
Amazon DynamoDB get, put, update or delete an item
Amazon ECS/Fargate run an ECS task and waits for it to complete
Amazon SNS publish a message to a SNS topic
Amazon SQS send a SQS message
AWS Glue start a Glue job
Amazon SageMaker create a training or transform job
Build Visual Workflows from State Types
Task
Choice
Fail
Parallel
Image Recognition and Processing Backend
Task
Choice
Fail
Parallel
https://github.com/awslabs/lambda-refarch-imagerecognition
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS Step Functions Demo
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS Step Functions Case Studies
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Vending Pass problem
1. Thirsty consumer presents
card, can buy a drink with
Vending Pass or debit
2. But mobile wallet display can
get out of sync under certain
conditions
3.
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Vending Pass problem
• Just wait for backend
to catch up
• Create a two-step state
machine:
• Wait (90 seconds)
• Update mobile wallet
• Cheap and simple!
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
• Transcode 350 clips/day into
14 formats, fast
• It’s all done with FFmpeg. The
processing time is just about
100% of the video length
• Aargh!
Video processing problem
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
• Derive keyframe locations
within the source
• Split the source at the
keyframes
• Process segments (typically
0.5 sec per) in parallel
• Concatenate segments
• Elapsed time: ~20 min down
to ~2 minutes
Video processing solution
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Takeaways
Use Amazon S3 data events
to trigger parallel Lambda
processing: win
Use Amazon S3
URLs to stream
video to
Lambda: win
Scaling to 1,000
Lambdas, rather
than 1,000 EC2
instances: win
Process video
segments in
parallel: win
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
More state machines
Image Recognition and Processing BackendEBS Snapshot Management
https://aws.amazon.com/step-functions/getting-started
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Lambda Layers
© 2019, Amazon Web Services, Inc. or its Affiliates.
Lambda Layers
Lets functions easily share code: Upload layer
once, reference within any function
Promote separation of responsibilities, lets
developers iterate faster on writing business logic
Built in support for secure sharing by ecosystem
© 2019, Amazon Web Services, Inc. or its Affiliates.
Using Lambda Layers
• Put common components in a ZIP file and
upload it as a Lambda Layer
• Layers are immutable and can be versioned
to manage updates
• When a version is deleted or permissions to
use it are revoked, functions that used it
previously will continue to work, but you
won’t be able to create new ones
• You can reference up to five layers, one of
which can optionally be a custom runtime
Lambda
Layers
arn:aws:lambda:region:accountId:layer:shared-lib
Lambda
Layers
arn:aws:lambda:region:accountId:layer:shared-lib:2
Lambda
Layers
arn:aws:lambda:region:accountId:layer:shared-lib:3
© 2019, Amazon Web Services, Inc. or its Affiliates.
Lambda Runtime API
Bring any Linux compatible language runtime
Powered by new Runtime API - Codifies the
runtime calling conventions and integration points
At launch, custom runtimes powering Ruby
support in AWS Lambda, more runtimes from
partners (like Erlang)
Custom runtimes distributed as “layers”
Rule
Stack
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
PHP Runtime Demo
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Thank You!
Boaz Ziniman
Technical Evangelist - Amazon Web Services
@ziniman
boaz.ziniman.aws
ziniman

More Related Content

PDF
Devops on serverless
PDF
The serverless LAMP stack
PDF
Continuous Integration and Continuous Delivery for your serverless apps - Seb...
PDF
"Automating AWS Infrastructure with PowerShell", Martin Beeby, AWS Dev Day Ky...
PDF
Ci/CD for AWS Lambda Projects - JLM CTO Club
PDF
20201012 - Serverless Architecture Conference - Deploying serverless applicat...
PPTX
Serverless Applications with AWS SAM
PPTX
Serverless Developer Experience I AWS Dev Day 2018
Devops on serverless
The serverless LAMP stack
Continuous Integration and Continuous Delivery for your serverless apps - Seb...
"Automating AWS Infrastructure with PowerShell", Martin Beeby, AWS Dev Day Ky...
Ci/CD for AWS Lambda Projects - JLM CTO Club
20201012 - Serverless Architecture Conference - Deploying serverless applicat...
Serverless Applications with AWS SAM
Serverless Developer Experience I AWS Dev Day 2018

More from Boaz Ziniman (20)

PDF
AWS Cost Optimization - JLM
PDF
What can you do with Serverless in 2020
PDF
Six ways to reduce your AWS bill
PDF
From Cloud to Edge & back again
PDF
Modern Applications Development on AWS
PDF
Enriching your app with Image recognition and AWS AI services Hebrew Webinar
PDF
AI Services and Serverless Workshop
PDF
Drive Down the Cost of your Data Lake by Using the Right Data Tiering
PDF
Breaking Voice and Language Barriers with AI - Chatbot Summit Tel Aviv
PDF
Websites Go Serverless - ServerlessDays TLV 2019
PDF
SKL208 - Turbocharge your Business with AI and Machine Learning - Tel Aviv Su...
PDF
AIM301 - Breaking Language Barriers With AI - Tel Aviv Summit 2019
PDF
Breaking Language Barriers with AI - AWS Summit
PDF
Websites go Serverless - AWS Summit Berlin
PDF
AWS Lambda updates from re:Invent
PDF
Artificial Intelligence for Developers - OOP Munich
PDF
Introduction to Serverless Computing - OOP Munich
PDF
IoT from Cloud to Edge & Back Again - WebSummit 2018
PDF
Breaking Language Barriers with AI - Web Summit 2018
PDF
How Websites go Serverless - WebSummit Lisbon 2018
AWS Cost Optimization - JLM
What can you do with Serverless in 2020
Six ways to reduce your AWS bill
From Cloud to Edge & back again
Modern Applications Development on AWS
Enriching your app with Image recognition and AWS AI services Hebrew Webinar
AI Services and Serverless Workshop
Drive Down the Cost of your Data Lake by Using the Right Data Tiering
Breaking Voice and Language Barriers with AI - Chatbot Summit Tel Aviv
Websites Go Serverless - ServerlessDays TLV 2019
SKL208 - Turbocharge your Business with AI and Machine Learning - Tel Aviv Su...
AIM301 - Breaking Language Barriers With AI - Tel Aviv Summit 2019
Breaking Language Barriers with AI - AWS Summit
Websites go Serverless - AWS Summit Berlin
AWS Lambda updates from re:Invent
Artificial Intelligence for Developers - OOP Munich
Introduction to Serverless Computing - OOP Munich
IoT from Cloud to Edge & Back Again - WebSummit 2018
Breaking Language Barriers with AI - Web Summit 2018
How Websites go Serverless - WebSummit Lisbon 2018
Ad

Recently uploaded (20)

PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
PPTX
Big Data Technologies - Introduction.pptx
PPT
Teaching material agriculture food technology
PDF
Advanced Soft Computing BINUS July 2025.pdf
PDF
KodekX | Application Modernization Development
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PPTX
Cloud computing and distributed systems.
PDF
Empathic Computing: Creating Shared Understanding
PDF
Electronic commerce courselecture one. Pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Advanced IT Governance
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Approach and Philosophy of On baking technology
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Network Security Unit 5.pdf for BCA BBA.
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
Big Data Technologies - Introduction.pptx
Teaching material agriculture food technology
Advanced Soft Computing BINUS July 2025.pdf
KodekX | Application Modernization Development
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
Cloud computing and distributed systems.
Empathic Computing: Creating Shared Understanding
Electronic commerce courselecture one. Pdf
NewMind AI Weekly Chronicles - August'25 Week I
Advanced IT Governance
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Approach and Philosophy of On baking technology
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Reach Out and Touch Someone: Haptics and Empathic Computing
The Rise and Fall of 3GPP – Time for a Sabbatical?
Network Security Unit 5.pdf for BCA BBA.
Ad

Serverless Beyond Functions - CTO Club Made in JLM

  • 1. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Boaz Ziniman - Technical Evangelist Amazon Web Service Serverless Beyond Functions @ziniman boaz.ziniman.aws ziniman
  • 2. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 3. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Serverless applications Services (anything) Changes in data state Requests to endpoints Changes in resource state Event source Function Node.js Python Java C# / F# / PowerShell Go Ruby Runtime API
  • 4. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Anatomy of a Lambda function Handler() function Function to be executed upon invocation Event object Data sent during Lambda function Invocation Context object Methods available to interact with runtime information (request ID, log group, more) import json def lambda_handler(event, context): # TODO implement return { 'statusCode': 200, 'body': json.dumps('Hello World!') }
  • 5. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. “I know how to build a serverless function, now what?”
  • 6. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Agenda • Orchestration • CI/CD • Step Functions • Layers
  • 7. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Project Orchestration
  • 8. © 2019, Amazon Web Services, Inc. or its Affiliates. Start with a framework AWS Chalice AWS Amplify AWS SAM AWS: Third-party: Serverless Framework
  • 10. © 2019, Amazon Web Services, Inc. or its Affiliates. AWS Serverless Application Model (SAM) AWS CloudFormation extension optimized for serverless Special serverless resource types: Functions, APIs, SimpleTables, Layers, and Applications Supports anything AWS CloudFormation supports Open specification (Apache 2.0) https://aws.amazon.com/serverless/sam
  • 11. © 2019, Amazon Web Services, Inc. or its Affiliates. AWS Serverless Application Model (SAM) AWSTemplateFormatVersion: '2010-09-09’ Transform: AWS::Serverless-2016-10-31 Resources: GetFunction: Type: AWS::Serverless::Function Properties: Handler: index.get Runtime: nodejs8.10 CodeUri: src/ Policies: - DynamoDBReadPolicy: TableName: !Ref MyTable Events: GetResource: Type: Api Properties: Path: /resource/{resourceId} Method: get MyTable: Type: AWS::Serverless::SimpleTable Just 20 lines to create: • Lambda function • IAM role • API Gateway • DynamoDB table O pen Source
  • 12. © 2019, Amazon Web Services, Inc. or its Affiliates. Use SAM CLI to package and deploy SAM templates pip install --user aws-sam-cli sam init --name my-app --runtime python cd my-app/ sam local ... # generate-event/invoke/start-api/start-lambda sam validate # The SAM template sam build # Depending on the runtime sam package --s3-bucket my-packages-bucket --output-template-file packaged.yaml sam deploy --template-file packaged.yaml --stack-name my-stack-prod sam logs -n MyFunction --stack-name my-stack-prod -t # Tail sam publish # To the Serverless Application Repository O pen Source CodePipeline Use CloudFormation deployment actions with any SAM application Jenkins Use SAM CLI plugin
  • 13. © 2019, Amazon Web Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates.
  • 14. © 2019, Amazon Web Services, Inc. or its Affiliates. With the AWS Serverless Application Repository: Developers can… • Discover and deploy ready-made apps and code samples • Combine applications in the app repository with their own via Nested Applications • Customize open-source apps to get started quickly • Share apps privately or publish apps for public use
  • 15. © 2019, Amazon Web Services, Inc. or its Affiliates. TweetSource: Type: AWS::Serverless::Application Properties: Location: ApplicationId: arn:aws:serverlessrepo:... SemanticVersion: 2.0.0 Parameters: TweetProcessorFunctionName: !Ref MyFunction SearchText: '#serverless -filter:nativeretweets' Nested apps to simplify solving recurring problems Standard Component Custom Business Logic Polling schedule (CloudWatch Events rule) trigger TwitterProcessor SearchCheckpoint TwitterSearchPoller Twitter Search API
  • 16. © 2019, Amazon Web Services, Inc. or its Affiliates. AWS Lambda Environment Variables • Key-value pairs that you can dynamically pass to your function • Available via standard environment variable APIs such as process.env for Node.js or os.environ for Python • Can optionally be encrypted via AWS Key Management Service (KMS) • Allows you to specify in IAM what roles have access to the keys to decrypt the information • Useful for creating environments per stage (i.e. dev, testing, production)
  • 17. © 2019, Amazon Web Services, Inc. or its Affiliates. Amazon API Gateway Stage Variables Stage variables act like environment variables • Use stage variables to store configuration values • Stage variables are available in the $context object • Values are accessible from most fields in API Gateway • Lambda function ARN • HTTP endpoint • Custom authorizer function name • Parameter mappings Amazon API Gateway
  • 18. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. CI/CD for Serverless
  • 19. © 2019, Amazon Web Services, Inc. or its Affiliates. Source Build Test Production Continuous Integration / Continuous Deployment
  • 20. © 2019, Amazon Web Services, Inc. or its Affiliates. Serverless deployments Code StackPackage Deploy Template
  • 21. © 2019, Amazon Web Services, Inc. or its Affiliates. Serverless deployments with a test environment Code Test Stack Package Deploy Template Feedback Production Stack Deploy
  • 22. © 2019, Amazon Web Services, Inc. or its Affiliates. MyLambdaFunction: Type: AWS::Serverless::Function Properties: Handler: index.handler Runtime: nodejs6.10 AutoPublishAlias: !Ref ENVIRONMENT DeploymentPreference: Type: Linear10PercentEvery10Minutes Alarms: # A list of alarms that you want to monitor - !Ref AliasErrorMetricGreaterThanZeroAlarm - !Ref LatestVersionErrorMetricGreaterThanZeroAlarm Hooks: # Validation Lambda functions that are run before & after traffic shifting PreTraffic: !Ref PreTrafficLambdaFunction PostTraffic: !Ref PostTrafficLambdaFunction AWS SAM + Safe Deployments
  • 23. © 2019, Amazon Web Services, Inc. or its Affiliates. CodeDeploy – Lambda deployments in SAM templates Resources: GetFunction: Type: AWS::Serverless::Function Properties: AutoPublishAlias: live DeploymentPreference: Type: Canary10Percent10Minutes Alarms: - !Ref ErrorsAlarm - !Ref LatencyAlarm Hooks: PreTraffic: !Ref PreTrafficHookFunction PostTraffic: !Ref PostTrafficHookFunction Canary10Percent30Minutes Canary10Percent5Minutes Canary10Percent10Minutes Canary10Percent15Minutes Linear10PercentEvery10Minutes Linear10PercentEvery1Minute Linear10PercentEvery2Minutes Linear10PercentEvery3Minutes AllAtOnce
  • 24. © 2019, Amazon Web Services, Inc. or its Affiliates. Alarms: # A list of alarms that you want to monitor - !Ref AliasErrorMetricGreaterThanZeroAlarm - !Ref LatestVersionErrorMetricGreaterThanZeroAlarm Hooks: # Validation Lambda functions that are run before & after traffic shifting PreTraffic: !Ref PreTrafficLambdaFunction PostTraffic: !Ref PostTrafficLambdaFunction AWS Lambda Alias Traffic Shifting & AWS SAM Note: You can specify a maximum of 10 alarms In SAM:
  • 25. © 2019, Amazon Web Services, Inc. or its Affiliates. CodeDeploy – Lambda canary deployment API Gateway Lambda function weighted alias “live” v1 Lambda function code 100%
  • 26. © 2019, Amazon Web Services, Inc. or its Affiliates. CodeDeploy – Lambda canary deployment API Gateway Lambda function weighted alias “live” v1 code100% Run PreTraffic hook against v2 code before it receives traffic v2 code0%
  • 27. © 2019, Amazon Web Services, Inc. or its Affiliates. CodeDeploy – Lambda canary deployment API Gateway Lambda function weighted alias “live” v1 code90% Wait for 10 minutes, roll back in case of alarm v2 code10%
  • 28. © 2019, Amazon Web Services, Inc. or its Affiliates. CodeDeploy – Lambda canary deployment API Gateway Lambda function weighted alias “live” v1 code0% Run PostTraffic hook and complete deployment v2 code100%
  • 29. © 2019, Amazon Web Services, Inc. or its Affiliates. API Gateway canary stage API Gateway Production stage v1 code v2 code 99.5% 0.5% Canary stage
  • 30. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Demo https://github.com/ziniman/aws-devday-storereply
  • 31. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Step Functions
  • 32. Application Lifecycle in AWS Step Functions Visualize in the Console Define in JSON Monitor Executions
  • 33. Define in JSON and Then Visualize in the Console { "Comment": "Hello World Example", "StartAt" : "HelloWorld", "States" : { "HelloWorld" : { "Type" : "Task", "Resource" : "${lambdaArn}", "End" : true } } }
  • 34. Execute One or One Million Start End HelloWorld Start End HelloWorld Start End HelloWorld Start End HelloWorld Start End HelloWorld Start End HelloWorld Start End HelloWorld Start End HelloWorld
  • 35. Maximum Execution Time AWS Lambda Functions 15 minutes AWS Step Functions State Machines 1 year
  • 36. Monitor Executions from the Console
  • 37. Seven State Types Task A single unit of work Choice Adds branching logic Parallel Fork and join the data across tasks Wait Delay for a specified time Fail Stops an execution and marks it as a failure Succeed Stops an execution successfully Pass Passes its input to its output
  • 38. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Step Functions Tasks – Service Integrations AWS Lambda invoke a Lambda function AWS Batch submit a Batch job and wait for it to complete Amazon DynamoDB get, put, update or delete an item Amazon ECS/Fargate run an ECS task and waits for it to complete Amazon SNS publish a message to a SNS topic Amazon SQS send a SQS message AWS Glue start a Glue job Amazon SageMaker create a training or transform job
  • 39. Build Visual Workflows from State Types Task Choice Fail Parallel
  • 40. Image Recognition and Processing Backend Task Choice Fail Parallel https://github.com/awslabs/lambda-refarch-imagerecognition
  • 41. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS Step Functions Demo
  • 42. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS Step Functions Case Studies
  • 43. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Vending Pass problem 1. Thirsty consumer presents card, can buy a drink with Vending Pass or debit 2. But mobile wallet display can get out of sync under certain conditions 3.
  • 44. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Vending Pass problem • Just wait for backend to catch up • Create a two-step state machine: • Wait (90 seconds) • Update mobile wallet • Cheap and simple!
  • 45. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. • Transcode 350 clips/day into 14 formats, fast • It’s all done with FFmpeg. The processing time is just about 100% of the video length • Aargh! Video processing problem
  • 46. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. • Derive keyframe locations within the source • Split the source at the keyframes • Process segments (typically 0.5 sec per) in parallel • Concatenate segments • Elapsed time: ~20 min down to ~2 minutes Video processing solution
  • 47. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Takeaways Use Amazon S3 data events to trigger parallel Lambda processing: win Use Amazon S3 URLs to stream video to Lambda: win Scaling to 1,000 Lambdas, rather than 1,000 EC2 instances: win Process video segments in parallel: win
  • 48. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. More state machines Image Recognition and Processing BackendEBS Snapshot Management https://aws.amazon.com/step-functions/getting-started
  • 49. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Lambda Layers
  • 50. © 2019, Amazon Web Services, Inc. or its Affiliates. Lambda Layers Lets functions easily share code: Upload layer once, reference within any function Promote separation of responsibilities, lets developers iterate faster on writing business logic Built in support for secure sharing by ecosystem
  • 51. © 2019, Amazon Web Services, Inc. or its Affiliates. Using Lambda Layers • Put common components in a ZIP file and upload it as a Lambda Layer • Layers are immutable and can be versioned to manage updates • When a version is deleted or permissions to use it are revoked, functions that used it previously will continue to work, but you won’t be able to create new ones • You can reference up to five layers, one of which can optionally be a custom runtime Lambda Layers arn:aws:lambda:region:accountId:layer:shared-lib Lambda Layers arn:aws:lambda:region:accountId:layer:shared-lib:2 Lambda Layers arn:aws:lambda:region:accountId:layer:shared-lib:3
  • 52. © 2019, Amazon Web Services, Inc. or its Affiliates. Lambda Runtime API Bring any Linux compatible language runtime Powered by new Runtime API - Codifies the runtime calling conventions and integration points At launch, custom runtimes powering Ruby support in AWS Lambda, more runtimes from partners (like Erlang) Custom runtimes distributed as “layers” Rule Stack
  • 53. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. PHP Runtime Demo
  • 54. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Thank You! Boaz Ziniman Technical Evangelist - Amazon Web Services @ziniman boaz.ziniman.aws ziniman