SlideShare a Scribd company logo
1 of 44
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Getting Started with AWS Lambda and Serverless Computing
George Mao,
Serverless Specialist
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Agenda
• What does it mean to be Serverless?
• What is AWS Lambda?
• What is Amazon API Gateway
• Use cases
• Best practices
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
What does it mean to be
Serverless?
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Servers
How will the application
handle server hardware failure?
How can I control
access from my servers?
When should I decide to
scale out my servers?
When should I decide to
scale up my servers?
What size servers are
right for my budget?
How much remaining
capacity do my servers have?
(AAHHHHHHHHH!!)
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Operations and management Scaling
Provisioning and utilization Availability and fault tolerance
Owning servers means dealing with ...
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Everybody knows this 3-tier app diagram
Presentation Tier Logic Tier Data Tier
Mobile App App Server Database
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Here is what that translates to in real life
http://media.amazonwebservices.com/architecturecenter/AWS_ac_ra_web_01.pdf
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
The Serverless stack
InternetMobile apps
AWS Lambda
functions
AWS
API Gateway
Other AWS
services
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
AWS Lambda
Amazon DynamoDB
Amazon SNS
Amazon API Gateway
Amazon SQS
Amazon KinesisAmazon S3
Compute and API Proxy
AWS X-Ray
AWS Step Functions
Services for Building Serverless Applications
Database, Storage, Orchestration, Analytics, Interprocess Messaging
Developer Tools
AWS CodeBuild
AWS CodePipelineAWS SAM
Third-Party Tools
Open Source
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
What is AWS Lambda?
Compute service that lets you run code without managing servers:
Scale, monitor, and, trigger on your behalf
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Introduction to AWS Lambda: Run code in response to events
FUNCTION SERVICES (ANYTHING)
Changes in
data state
Requests to
endpoints
Changes in
resource state
Node
Python
Java
C#
EVENT SOURCE
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Cost-effective and
efficient
No Infrastructure
to manage
Pay only for what you use
Bring Your
Own Code
Productivity focused compute platform to build powerful, dynamic, modular
applications in the cloud
Run code in standard
languages
Focus on business logic
Benefits of AWS Lambda
1 2 3
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
How it works
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Using AWS Lambda
Bring your own code
• Node.js, Java, Python, C#
• Bring your own libraries
(even native ones)
Simple resource model
• Select power rating from
128 MB to 1.5 GB
• CPU and network
allocated proportionately
Flexible use
• Synchronous or
asynchronous
• Integrated with other
AWS services
Flexible authorization
• Securely grant access to
resources and VPCs
• Fine-grained control for
invoking your functions
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Using AWS Lambda
Authoring functions
• WYSIWYG editor or
upload packaged .zip
• Third-party plugins
(Eclipse, Visual Studio,
SAM)
Monitoring and logging
• Metrics for requests,
errors, and throttles
• Built-in logs to Amazon
CloudWatch Logs
Programming model
• Use processes, threads,
/tmp, sockets normally
• AWS SDK built in
(Python and Node.js)
Stateless
• Persist data using
external storage
• No affinity or access to
underlying infrastructure
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
3 Easy Steps!
1. Write your code
1. Package/Upload to AWS Lambda
2. Define your Compute Requirements
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Amazon
S3
Amazon
DynamoDB
Amazon
Kinesis
AWS
CloudFormation
AWS
CloudTrail
Amazon
CloudWatch
Amazon
SNS
Amazon
SES
Amazon
API Gateway
Amazon
Cognito
Amazon
Alexa
Cron events
DATA STORES ENDPOINTS
REPOSITORIES EVENT/MESSAGE SERVICES
Event Sources that integrate with AWS Lambda
… and the list will continue to grow!
Amazon RDS
Aurora
New
AWS
CodeCommit
AWS Step
Functions
AWS IoT
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
AWS Lambda Pricing
• Buy compute time in
100 ms increments
• Low request charge
• No hourly, daily, or
monthly minimums
• No per-device fees
Never pay for idle!
Free Tier
1 million requests and 400,000 GB-secs of
compute every month, every customer
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
What is API Gateway?
Fully managed service that makes it easy for developers to:
create, publish, maintain, monitor, and secure
APIs at any scale.
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Introduction to Amazon API Gateway
Create a unified
API frontend for
multiple micro-
services
Authenticate and
authorize
requests to a
backend
DDoS protection
and throttling for
your backend
Throttle, meter,
and monetize API
usage by 3rd
party developers
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Amazon API Gateway: Serverless APIs
Internet
Mobile Apps
Websites
Services
AWS Lambda
functions
AWS
API Gateway
Cache
Endpoints on
Amazon EC2
All publicly
accessible
endpoints
Amazon
CloudWatch
Monitoring
Amazon
CloudFront
Amazon
API Gateway
Any other
AWS service
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Lets dive a little deeper
api-name/
/store/products
GET
OPTIONS
/store/{cart} POST
Store Lambda
Function
Mock
integration for
CORS support
AWS
Service
Proxy
https://my-api-id.execute-api.region-id.amazonaws.com/stage/api-name
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
What are Step Functions?
Makes it simple to:
Coordinate and run multistep applications
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
“I want to sequence functions”
“I want to select functions based on data”
I want to run functions in parallel
“I want to retry functions”
“I want to try/catch/finally”
“I want to run code for hours”
Orchestration for serverless apps
AWS Step Functions
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Benefits of Step Functions orchestration
Change and add steps
without writing code to
evolve applications and
innovate faster
Coordinate and visualize
Lambda functions as a series
of steps to quickly create
serverless apps
Automatically trigger and track
each step at scale
and handle errors with
built-in retry and fallback
Productivity AgilityResilience
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
AWS Step Functions
Easily coordinate multiple Lambda functions using visual workflows
Visualize in the
Console
Define in JSON Monitor
Executions
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Visual Workflows and Orchestration
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Visual Workflows and Orchestration
Sequential Steps Branching Steps Parallel Steps
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
JSON Based Templates
• Defined in JSON format
– Pass
– Task
– Choice
– Parallel
{
"Comment": "A Hello World example",
"StartAt": "HelloWorld",
"States": {
"HelloWorld": {
"Type": "Pass",
"Result": "Hello World!",
"End": true
}
}
}
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Serverless Use cases
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Common use cases
Web
Applications
• Static websites
• Complex web
apps
• Packages for
Flask and
Express
Data
Processing
• Real time
• MapReduce
• Batch
Chatbots
• Powering
chatbot logic
Backends
• Apps & services
• Mobile
• IoT
</></>
Amazon
Alexa
• Powering voice-
enabled apps
• Alexa Skills Kit
IT
Automation
• Policy engines
• Extending AWS
services
• Infrastructure
management
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Web Applications and Backends
App requests
over HTTPS
CRUD
operations
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Backend Order Processing
CloudWatch event
every 5 minutes
Lambda runs
for 5 minutesSQS queue
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
What to expect from the session
15-20 minutes of processing  now in seconds
2x order of magnitude for cost savings
https://www.youtube.com/watch?v=TXmkj2a0fRE
Nordstrom Recommendations
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
AWS Lambda use cases – Image Thumbnail Creation
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
AWS Lambda use cases – Data processing
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Best practices
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
AWS Lambda best practices
 Limit your function/code size
 Node – remember execution is asynchronous – event loop!
 500 MB /tmp directory provided to each function
 Don’t assume function will reuse underlying infrastructure
 But take advantage of it when it does occur
 You own the logs
 Include details from service-provided context
 Create custom metrics
 Operations-centric vs. business-centric
 Use environment variables
 Parameterize code and change parameters independent of code updates
 Use for securing credentials and keeping them out of code
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Additional best practices
 Externalize authorization to IAM roles whenever possible
 Least privilege and separate IAM roles
 Externalize configuration
 DynamoDB is great for this
 Take advantage of Dead Letter Queues
 Use to handle failed invocations
 Make sure your downstream setup “keeps up” with Lambda scaling
 Limit concurrency when talking to relational databases
 Be aware of service throttling
 Engage AWS Support to increase your limits
 Contact AWS Support before known large scaling events
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Best practice: Use versions and aliases
• Versions = immutable copies of code + properties
• Aliases = mutable pointers to versions
 Rollbacks
 Staged
promotions
 “Lock” behavior
for client
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
AWS CloudFormation brings:
• Infrastructure as code
• Easy to provision and manage a collection of related AWS resources
• Input .yaml file and output provisioned AWS resources
• Optimized for infrastructure
AWS SAM:
• CloudFormation extension optimized for serverless
• New serverless resources: functions, APIs, and tables
• Supports anything CloudFormation supports
• Open specification (Apache 2.0)
AWS Serverless Application Model (AWS SAM)
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
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
Properties:
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
responses: {}
swagger: '2.0'
CF template example – API triggering Lambda
AWSTemplateFormatVersion: '2010-09-09’
Transform: AWS::Serverless-2016-10-31
Resources:
GetHtmlFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://flourish-demo-bucket/todo_list.zip
Handler: index.gethtml
Runtime: nodejs4.3
Policies: AmazonDynamoDBReadOnlyAccess
Events:
GetHtml:
Type: Api
Properties:
Path: /{proxy+}
Method: ANY
ListTable:
Type: AWS::Serverless::SimpleTable
AWS SAM example – API triggering Lambda
AWS SAM: Less complexity, more power
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Q & A
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved
aws.amazon.com/activate
Everything and Anything Startups
Need to Get Started on AWS

More Related Content

What's hot

What's hot (20)

AWS Lambda
AWS LambdaAWS Lambda
AWS Lambda
 
FinOps - AWS Cost and Operational Efficiency - Pop-up Loft Tel Aviv
FinOps - AWS Cost and Operational Efficiency - Pop-up Loft Tel AvivFinOps - AWS Cost and Operational Efficiency - Pop-up Loft Tel Aviv
FinOps - AWS Cost and Operational Efficiency - Pop-up Loft Tel Aviv
 
Introduction to AWS Cost Management
Introduction to AWS Cost ManagementIntroduction to AWS Cost Management
Introduction to AWS Cost Management
 
AWS Security Best Practices and Design Patterns
AWS Security Best Practices and Design PatternsAWS Security Best Practices and Design Patterns
AWS Security Best Practices and Design Patterns
 
Getting Started with AWS Lambda and Serverless
Getting Started with AWS Lambda and ServerlessGetting Started with AWS Lambda and Serverless
Getting Started with AWS Lambda and Serverless
 
Serverless computing with AWS Lambda
Serverless computing with AWS Lambda Serverless computing with AWS Lambda
Serverless computing with AWS Lambda
 
AWS Enterprise Summit :: 클라우드 운영 - Cloud CoE, Cloud Ops, Cloud MSP (이원일 시니어 컨...
AWS Enterprise Summit :: 클라우드 운영 - Cloud CoE, Cloud Ops, Cloud MSP (이원일 시니어 컨...AWS Enterprise Summit :: 클라우드 운영 - Cloud CoE, Cloud Ops, Cloud MSP (이원일 시니어 컨...
AWS Enterprise Summit :: 클라우드 운영 - Cloud CoE, Cloud Ops, Cloud MSP (이원일 시니어 컨...
 
AWS Landing Zone Deep Dive (ENT350-R2) - AWS re:Invent 2018
AWS Landing Zone Deep Dive (ENT350-R2) - AWS re:Invent 2018AWS Landing Zone Deep Dive (ENT350-R2) - AWS re:Invent 2018
AWS Landing Zone Deep Dive (ENT350-R2) - AWS re:Invent 2018
 
Authoring and Deploying Serverless Applications with AWS SAM
Authoring and Deploying Serverless Applications with AWS SAMAuthoring and Deploying Serverless Applications with AWS SAM
Authoring and Deploying Serverless Applications with AWS SAM
 
Cost Optimisation on AWS
Cost Optimisation on AWSCost Optimisation on AWS
Cost Optimisation on AWS
 
Introduction to AWS Lambda and Serverless Applications
Introduction to AWS Lambda and Serverless ApplicationsIntroduction to AWS Lambda and Serverless Applications
Introduction to AWS Lambda and Serverless Applications
 
Module 2: Core AWS Compute and Storage Services - Virtual AWSome Day June 2018
Module 2: Core AWS Compute and Storage Services - Virtual AWSome Day June 2018Module 2: Core AWS Compute and Storage Services - Virtual AWSome Day June 2018
Module 2: Core AWS Compute and Storage Services - Virtual AWSome Day June 2018
 
AWS Control Tower
AWS Control TowerAWS Control Tower
AWS Control Tower
 
Cost Optimisation on AWS
Cost Optimisation on AWSCost Optimisation on AWS
Cost Optimisation on AWS
 
Getting Started with AWS Lambda Serverless Computing
Getting Started with AWS Lambda Serverless ComputingGetting Started with AWS Lambda Serverless Computing
Getting Started with AWS Lambda Serverless Computing
 
Introduction to the Well-Architected Framework and Tool - SVC208 - Anaheim AW...
Introduction to the Well-Architected Framework and Tool - SVC208 - Anaheim AW...Introduction to the Well-Architected Framework and Tool - SVC208 - Anaheim AW...
Introduction to the Well-Architected Framework and Tool - SVC208 - Anaheim AW...
 
Accelerating Your Cloud Migration Journey with MAP
Accelerating Your Cloud Migration Journey with MAPAccelerating Your Cloud Migration Journey with MAP
Accelerating Your Cloud Migration Journey with MAP
 
Serverless Architectures.pdf
Serverless Architectures.pdfServerless Architectures.pdf
Serverless Architectures.pdf
 
AWS 101
AWS 101AWS 101
AWS 101
 
Introduction to Serverless
Introduction to ServerlessIntroduction to Serverless
Introduction to Serverless
 

Similar to Getting Started with AWS Lambda and Serverless Computing

Similar to Getting Started with AWS Lambda and Serverless Computing (20)

Getting Started with Serverless Architectures
Getting Started with Serverless ArchitecturesGetting Started with Serverless Architectures
Getting Started with Serverless Architectures
 
Debugging Modern Applications: Introduction to AWS X-Ray
Debugging Modern Applications: Introduction to AWS X-RayDebugging Modern Applications: Introduction to AWS X-Ray
Debugging Modern Applications: Introduction to AWS X-Ray
 
Wild rydes serverless website workshop
Wild rydes   serverless website workshopWild rydes   serverless website workshop
Wild rydes serverless website workshop
 
Developing and Implementing APIs at Scale, the Servless Way - Ed Lima - AWS T...
Developing and Implementing APIs at Scale, the Servless Way - Ed Lima - AWS T...Developing and Implementing APIs at Scale, the Servless Way - Ed Lima - AWS T...
Developing and Implementing APIs at Scale, the Servless Way - Ed Lima - AWS T...
 
Getting Started with AWS Lambda & Serverless Computing
Getting Started with AWS Lambda & Serverless ComputingGetting Started with AWS Lambda & Serverless Computing
Getting Started with AWS Lambda & Serverless Computing
 
Serverless Development Deep Dive
Serverless Development Deep DiveServerless Development Deep Dive
Serverless Development Deep Dive
 
Building Serverless Microservices with AWS
Building Serverless Microservices with AWSBuilding Serverless Microservices with AWS
Building Serverless Microservices with AWS
 
Getting Started with Serverless Architectures
Getting Started with Serverless ArchitecturesGetting Started with Serverless Architectures
Getting Started with Serverless Architectures
 
Serverless APIs and you
Serverless APIs and youServerless APIs and you
Serverless APIs and you
 
Forza Computazionale e Applicazioni Serverless
Forza Computazionale e Applicazioni ServerlessForza Computazionale e Applicazioni Serverless
Forza Computazionale e Applicazioni Serverless
 
Serverless computing - Build and run applications without thinking about servers
Serverless computing - Build and run applications without thinking about serversServerless computing - Build and run applications without thinking about servers
Serverless computing - Build and run applications without thinking about servers
 
Raleigh DevDay 2017: Building serverless web applications
Raleigh DevDay 2017: Building serverless web applicationsRaleigh DevDay 2017: Building serverless web applications
Raleigh DevDay 2017: Building serverless web applications
 
Build and Deploy Serverless Applications with AWS SAM
Build and Deploy Serverless Applications with AWS SAM Build and Deploy Serverless Applications with AWS SAM
Build and Deploy Serverless Applications with AWS SAM
 
Build and run applications without thinking about servers
Build and run applications without thinking about serversBuild and run applications without thinking about servers
Build and run applications without thinking about servers
 
Modern Applications Web Day | Impress Your Friends with Your First Serverless...
Modern Applications Web Day | Impress Your Friends with Your First Serverless...Modern Applications Web Day | Impress Your Friends with Your First Serverless...
Modern Applications Web Day | Impress Your Friends with Your First Serverless...
 
Bootcamp: Getting Started on AWS
Bootcamp: Getting Started on AWSBootcamp: Getting Started on AWS
Bootcamp: Getting Started on AWS
 
Enterprise Cloud Adoption
Enterprise Cloud AdoptionEnterprise Cloud Adoption
Enterprise Cloud Adoption
 
Going Serverless at AWS Startup Day Bangalore
Going Serverless at AWS Startup Day Bangalore Going Serverless at AWS Startup Day Bangalore
Going Serverless at AWS Startup Day Bangalore
 
Building Serverless Enterprise Applications - SRV315 - Anaheim AWS Summit
Building Serverless Enterprise Applications - SRV315 - Anaheim AWS SummitBuilding Serverless Enterprise Applications - SRV315 - Anaheim AWS Summit
Building Serverless Enterprise Applications - SRV315 - Anaheim AWS Summit
 
Beyond Infrastructure for SAP on AWS (GPSTEC322) - AWS re:Invent 2018
Beyond Infrastructure for SAP on AWS (GPSTEC322) - AWS re:Invent 2018Beyond Infrastructure for SAP on AWS (GPSTEC322) - AWS re:Invent 2018
Beyond Infrastructure for SAP on AWS (GPSTEC322) - AWS re:Invent 2018
 

More from Amazon 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 AWS
Amazon 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 Deck
Amazon Web Services
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without servers
Amazon 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
 

More from 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
 

Getting Started with AWS Lambda and Serverless Computing

  • 1. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved Getting Started with AWS Lambda and Serverless Computing George Mao, Serverless Specialist
  • 2. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved Agenda • What does it mean to be Serverless? • What is AWS Lambda? • What is Amazon API Gateway • Use cases • Best practices
  • 3. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved What does it mean to be Serverless?
  • 4. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved Servers How will the application handle server hardware failure? How can I control access from my servers? When should I decide to scale out my servers? When should I decide to scale up my servers? What size servers are right for my budget? How much remaining capacity do my servers have? (AAHHHHHHHHH!!)
  • 5. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved Operations and management Scaling Provisioning and utilization Availability and fault tolerance Owning servers means dealing with ...
  • 6. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved Everybody knows this 3-tier app diagram Presentation Tier Logic Tier Data Tier Mobile App App Server Database
  • 7. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved Here is what that translates to in real life http://media.amazonwebservices.com/architecturecenter/AWS_ac_ra_web_01.pdf
  • 8. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved The Serverless stack InternetMobile apps AWS Lambda functions AWS API Gateway Other AWS services
  • 9. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved AWS Lambda Amazon DynamoDB Amazon SNS Amazon API Gateway Amazon SQS Amazon KinesisAmazon S3 Compute and API Proxy AWS X-Ray AWS Step Functions Services for Building Serverless Applications Database, Storage, Orchestration, Analytics, Interprocess Messaging Developer Tools AWS CodeBuild AWS CodePipelineAWS SAM Third-Party Tools Open Source
  • 10. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved What is AWS Lambda? Compute service that lets you run code without managing servers: Scale, monitor, and, trigger on your behalf
  • 11. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved Introduction to AWS Lambda: Run code in response to events FUNCTION SERVICES (ANYTHING) Changes in data state Requests to endpoints Changes in resource state Node Python Java C# EVENT SOURCE
  • 12. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved Cost-effective and efficient No Infrastructure to manage Pay only for what you use Bring Your Own Code Productivity focused compute platform to build powerful, dynamic, modular applications in the cloud Run code in standard languages Focus on business logic Benefits of AWS Lambda 1 2 3
  • 13. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved How it works
  • 14. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved Using AWS Lambda Bring your own code • Node.js, Java, Python, C# • Bring your own libraries (even native ones) Simple resource model • Select power rating from 128 MB to 1.5 GB • CPU and network allocated proportionately Flexible use • Synchronous or asynchronous • Integrated with other AWS services Flexible authorization • Securely grant access to resources and VPCs • Fine-grained control for invoking your functions
  • 15. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved Using AWS Lambda Authoring functions • WYSIWYG editor or upload packaged .zip • Third-party plugins (Eclipse, Visual Studio, SAM) Monitoring and logging • Metrics for requests, errors, and throttles • Built-in logs to Amazon CloudWatch Logs Programming model • Use processes, threads, /tmp, sockets normally • AWS SDK built in (Python and Node.js) Stateless • Persist data using external storage • No affinity or access to underlying infrastructure
  • 16. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved 3 Easy Steps! 1. Write your code 1. Package/Upload to AWS Lambda 2. Define your Compute Requirements
  • 17. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved Amazon S3 Amazon DynamoDB Amazon Kinesis AWS CloudFormation AWS CloudTrail Amazon CloudWatch Amazon SNS Amazon SES Amazon API Gateway Amazon Cognito Amazon Alexa Cron events DATA STORES ENDPOINTS REPOSITORIES EVENT/MESSAGE SERVICES Event Sources that integrate with AWS Lambda … and the list will continue to grow! Amazon RDS Aurora New AWS CodeCommit AWS Step Functions AWS IoT
  • 18. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved AWS Lambda Pricing • Buy compute time in 100 ms increments • Low request charge • No hourly, daily, or monthly minimums • No per-device fees Never pay for idle! Free Tier 1 million requests and 400,000 GB-secs of compute every month, every customer
  • 19. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved What is API Gateway? Fully managed service that makes it easy for developers to: create, publish, maintain, monitor, and secure APIs at any scale.
  • 20. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved Introduction to Amazon API Gateway Create a unified API frontend for multiple micro- services Authenticate and authorize requests to a backend DDoS protection and throttling for your backend Throttle, meter, and monetize API usage by 3rd party developers
  • 21. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved Amazon API Gateway: Serverless APIs Internet Mobile Apps Websites Services AWS Lambda functions AWS API Gateway Cache Endpoints on Amazon EC2 All publicly accessible endpoints Amazon CloudWatch Monitoring Amazon CloudFront Amazon API Gateway Any other AWS service
  • 22. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved Lets dive a little deeper api-name/ /store/products GET OPTIONS /store/{cart} POST Store Lambda Function Mock integration for CORS support AWS Service Proxy https://my-api-id.execute-api.region-id.amazonaws.com/stage/api-name
  • 23. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved What are Step Functions? Makes it simple to: Coordinate and run multistep applications
  • 24. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved “I want to sequence functions” “I want to select functions based on data” I want to run functions in parallel “I want to retry functions” “I want to try/catch/finally” “I want to run code for hours” Orchestration for serverless apps AWS Step Functions
  • 25. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved Benefits of Step Functions orchestration Change and add steps without writing code to evolve applications and innovate faster Coordinate and visualize Lambda functions as a series of steps to quickly create serverless apps Automatically trigger and track each step at scale and handle errors with built-in retry and fallback Productivity AgilityResilience
  • 26. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved AWS Step Functions Easily coordinate multiple Lambda functions using visual workflows Visualize in the Console Define in JSON Monitor Executions
  • 27. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved Visual Workflows and Orchestration
  • 28. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved Visual Workflows and Orchestration Sequential Steps Branching Steps Parallel Steps
  • 29. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved JSON Based Templates • Defined in JSON format – Pass – Task – Choice – Parallel { "Comment": "A Hello World example", "StartAt": "HelloWorld", "States": { "HelloWorld": { "Type": "Pass", "Result": "Hello World!", "End": true } } }
  • 30. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved Serverless Use cases
  • 31. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved Common use cases Web Applications • Static websites • Complex web apps • Packages for Flask and Express Data Processing • Real time • MapReduce • Batch Chatbots • Powering chatbot logic Backends • Apps & services • Mobile • IoT </></> Amazon Alexa • Powering voice- enabled apps • Alexa Skills Kit IT Automation • Policy engines • Extending AWS services • Infrastructure management
  • 32. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved Web Applications and Backends App requests over HTTPS CRUD operations
  • 33. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved Backend Order Processing CloudWatch event every 5 minutes Lambda runs for 5 minutesSQS queue
  • 34. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved What to expect from the session 15-20 minutes of processing  now in seconds 2x order of magnitude for cost savings https://www.youtube.com/watch?v=TXmkj2a0fRE Nordstrom Recommendations
  • 35. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved AWS Lambda use cases – Image Thumbnail Creation
  • 36. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved AWS Lambda use cases – Data processing
  • 37. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved Best practices
  • 38. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved AWS Lambda best practices  Limit your function/code size  Node – remember execution is asynchronous – event loop!  500 MB /tmp directory provided to each function  Don’t assume function will reuse underlying infrastructure  But take advantage of it when it does occur  You own the logs  Include details from service-provided context  Create custom metrics  Operations-centric vs. business-centric  Use environment variables  Parameterize code and change parameters independent of code updates  Use for securing credentials and keeping them out of code
  • 39. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved Additional best practices  Externalize authorization to IAM roles whenever possible  Least privilege and separate IAM roles  Externalize configuration  DynamoDB is great for this  Take advantage of Dead Letter Queues  Use to handle failed invocations  Make sure your downstream setup “keeps up” with Lambda scaling  Limit concurrency when talking to relational databases  Be aware of service throttling  Engage AWS Support to increase your limits  Contact AWS Support before known large scaling events
  • 40. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved Best practice: Use versions and aliases • Versions = immutable copies of code + properties • Aliases = mutable pointers to versions  Rollbacks  Staged promotions  “Lock” behavior for client
  • 41. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved AWS CloudFormation brings: • Infrastructure as code • Easy to provision and manage a collection of related AWS resources • Input .yaml file and output provisioned AWS resources • Optimized for infrastructure AWS SAM: • CloudFormation extension optimized for serverless • New serverless resources: functions, APIs, and tables • Supports anything CloudFormation supports • Open specification (Apache 2.0) AWS Serverless Application Model (AWS SAM)
  • 42. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved 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 Properties: 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 responses: {} swagger: '2.0' CF template example – API triggering Lambda AWSTemplateFormatVersion: '2010-09-09’ Transform: AWS::Serverless-2016-10-31 Resources: GetHtmlFunction: Type: AWS::Serverless::Function Properties: CodeUri: s3://flourish-demo-bucket/todo_list.zip Handler: index.gethtml Runtime: nodejs4.3 Policies: AmazonDynamoDBReadOnlyAccess Events: GetHtml: Type: Api Properties: Path: /{proxy+} Method: ANY ListTable: Type: AWS::Serverless::SimpleTable AWS SAM example – API triggering Lambda AWS SAM: Less complexity, more power
  • 43. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved Q & A
  • 44. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved aws.amazon.com/activate Everything and Anything Startups Need to Get Started on AWS