SlideShare a Scribd company logo
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Serverless Architecture Patterns
And Best Practices
Arun Gupta
Principal Technologist
argu@amazon.com
@arungupta
arun-gupta
Adrian Hornsby
Cloud Architecture Evangelist
adhorn@amazon.com
@adhorn
adhorn
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Agenda
1. Serverless Key Concepts
2. Lambda Basics
3. Lambda Best Practices
4. Serverless Application Model
5. CI/CD using CodeStar
6. Monitoring
7. Event Processing
8. Real-time Streaming
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Serverless Key Concepts
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
No servers to provision
or manage
Scales with usage
Never pay for idle Availability and fault tolerance
built in
Serverless means…
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Spectrum of AWS offerings
AWS
Lambda
Amazon
Kinesis
Amazon
S3
Amazon API
Gateway
Amazon
SQS
Amazon
DynamoDB
AWS IoT
Amazon
EMR
Amazon
ElastiCache
Amazon
RDS
Amazon
Redshift
Amazon ES
Managed Serverless
Amazon EC2
Microsoft SQL
Server
“On EC2”
Amazon
Cognito
Amazon
CloudWatch
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Lambda Basics
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Using AWS Lambda
Bring your own code
• Node.js, Java, Python, C#,
Go
• Bring your own libraries
(even native ones)
Simple resource model
• Select power rating from
128 MB to 3 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
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Lambda execution model
Synchronous (push) Asynchronous (event) Stream-based
Amazon
API Gateway
AWS Lambda
function
Amazon
DynamoDB
Amazon
SNS
/api/hello
AWS Lambda
function
Amazon
S3
reqs
Amazon
Kinesis
changes
AWS Lambda
service
function
© 2017, 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, etc.)
public String handleRequest(Book book, Context context) {
saveBook(book);
return book.getName() + " saved!";
}
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Lambda Best Practices
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Lambda Best Practices
• Separate the Lambda handler from core logic
public class BookPostHandler implements RequestHandler<Book, String> {
static DynamoDBMapper mapper = DDBUtil.getMapper();
public String handleRequest(Book book, Context context) {
System.out.println("Adding book: " + book);
saveBook(book);
return book.getName() + " saved!";
}
private void saveBook(Book book) {
mapper.save(book);
}
}
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Lambda Best Practices
• Minimize package size to necessities
<dependencies>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-lambda-java-core -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-dynamodb -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-dynamodb</artifactId>
<version>1.11.127</version>
</dependency>
</dependencies>
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Lambda Best Practices
• Use Environment Variables to modify operational behavior
String region = System.getenv("AWS_REGION");
. . .
String bucket = System.getenv(“S3_BUCKET”);
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Lambda Best Practices
• Self-contain dependencies in your function package
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Lambda Best Practices
• Leverage “Max Memory Used” to right-size your functions
• Calculate 1000x all prime numbers < 1m
Memory Compute time Cost
128 MB 11.722965 secs $0.024628
256 MB 6.678945 secs $0.028035
512 MB 3.194954 secs $0.026830
1024 MB 1.465984sec $0.024638
https://github.com/jconning/lambda-cpu-cost
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Lambda Best Practices
• Delete large unused functions (75GB limit per region)
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Meet
SAM!
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Serverless Application Model
CloudFormation extension optimized for serverless
New serverless resource types: functions, APIs, and tables
Supports anything CloudFormation supports
Open specification (Apache 2.0)
https://github.com/awslabs/serverless-application-model
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
SAM Template
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Simple CRUD webservice.
Resources:
GetFunction:
Type: AWS::Serverless::Function
Properties:
Handler: org.sample.aws.samlocal.BookGetHandler
Runtime: java8
CodeUri: ./target/sam-local-java-1.0-SNAPSHOT.jar
Policies: AmazonDynamoDBReadOnlyAccess
Timeout: 30
Environment:
Variables:
TABLE_NAME: !Ref Table
Events:
GetResource:
Type: Api
Properties:
Path: /books
Method: get
Table:
Type: AWS::Serverless::SimpleTable
}
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
SAM Commands
Package
Creates a deployment package (.zip file)
Uploads deployment package to an S3 bucket
Adds a CodeUri property with S3 URI
Deploy
Creates CloudFormation resources
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
SAM Local
• CLI for local testing of Serverless apps
• Works with Lambda functions and
“proxy style” APIs
• Response object and function logs
available on your local machine
• Currently supports Java, Node.js and
Python
• Accepting PRs
https://github.com/awslabs/aws-sam-local
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
CI/CD using AWS CodeStar, AWS
CodeBuild and AWS CodePipeline
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Monitoring
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS X-Ray Integration with Serverless
• Lambda instruments incoming requests for all
supported languages
• Lambda runs the X-Ray daemon on all languages
with an SDK
var AWSXRay = require(‘aws-xray-sdk-core‘);
AWSXRay.middleware.setSamplingRules(‘sampling-rules.json’);
var AWS = AWSXRay.captureAWS(require(‘aws-sdk’));
S3Client = AWS.S3();
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
X-Ray Trace Example
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Event Processing
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Event driven
A B CEvent A on B triggers C
Invocation
Lambda functions
Action
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Event-driven platform
S3 event
notifications
DynamoDB
Streams
Kinesis
events
Cognito
events
SNS
events
Custom
events
CloudTrail
events
LambdaDynamoDB
Kinesis S3
Any custom
Invoked in response to events
- Changes in data
- Changes in state
Redshift
SNS
Access any service,
including your own
Such as…
Lambda functions
CloudWatch
events
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Event-driven actions
Lambda:
Resize Images
Users upload photos
S3:
Source Bucket
S3:
Destination Bucket
Triggered on
PUTs
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS Step Functions:
Orchestrate a Serverless processing
workflow using AWS Lambda
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Real-time Streaming
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
https://aws.amazon.com/solutions/case-studies/supercell/
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon Kinesis makes it easy to work with real-time
streaming data
Amazon Kinesis
Streams
• For Technical Developers
• Collect and stream data
for ordered, replay-able,
real-time processing
Amazon Kinesis
Firehose
• For all developers, data
scientists
• Easily load massive
volumes of streaming data
into Amazon S3, Redshift,
ElasticSearch
Amazon Kinesis
Analytics
• For all developers, data
scientists
• Easily analyze data
streams using standard
SQL queries
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Producers Consumers
Shard 1
Shard 2
Shard n
Shard 3
…
…
Write: 1MB Read: 2MB
** A shard is a group of data records in a stream
Amazon Kinesis
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Processing a Kinesis Streams with AWS Lambda
Shard 1 Shard 2 Shard 3 Shard 4 Shard n
Kinesis Stream
. . .
. . .
• Single instance of Lambda function per shard
• Polls shard once per second
• Lambda function instances created and removed automatically as stream is scaled
Gets Records
1x per sec
10k records
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Kinesis Analytics
Use SQL to build real-time applications
Easily write SQL code to process streaming data
Connect to streaming source
Continuously deliver SQL results
Real-time Analytics Demo
http://quad.adhorn.me
Real-time analytics
Amazon
Kinesis
Stream
Amazon
Kinesis
Analytics
Amazon
Cognito
Amazon
Kinesis
Stream
Amazon
DynamoDB
Amazon
Lambda
AmazonS3
JavaScriptSDK
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Further Reading
Serverless Architectures with AWS Lambda
https://d1.awsstatic.com/whitepapers/serverless-architectures-with-aws-lambda.pdf
Optimizing Enterprise Economics with Serverless Architectures
https://d0.awsstatic.com/whitepapers/optimizing-enterprise-economics-serverless-architectures.pdf
Serverless Applications Lens - AWS Well-Architected Framework
https://d1.awsstatic.com/whitepapers/architecture/AWS-Serverless-Applications-Lens.pdf
Streaming Data Solutions on AWS with Amazon Kinesis
https://d1.awsstatic.com/whitepapers/whitepaper-streaming-data-solutions-on-aws-with-amazon-kinesis.pdf
AWS Serverless Multi-Tier Architectures
https://d1.awsstatic.com/whitepapers/AWS_Serverless_Multi-Tier_Archiectures.pdf
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
More info:
https://aws.amazon.com/serverless/
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Thank you!

More Related Content

PDF
Introduction to Serverless computing and AWS Lambda - Floor28
PDF
Building Serverless Microservices with AWS
PDF
Cutting to the chase for Machine Learning Analytics Ecosystem & AWS Lake Form...
PPTX
Gluecon 2018 - The Best Practices and Hard Lessons Learned of Serverless Appl...
PDF
Introduzione a GraphQL
PDF
Serverless Architectural Patterns 
and Best Practices - Madhu Shekar - AWS
PPTX
Serverless in Action on AWS
PPTX
Getting started with Serverless on AWS
Introduction to Serverless computing and AWS Lambda - Floor28
Building Serverless Microservices with AWS
Cutting to the chase for Machine Learning Analytics Ecosystem & AWS Lake Form...
Gluecon 2018 - The Best Practices and Hard Lessons Learned of Serverless Appl...
Introduzione a GraphQL
Serverless Architectural Patterns 
and Best Practices - Madhu Shekar - AWS
Serverless in Action on AWS
Getting started with Serverless on AWS

Similar to Serverless architecture-patterns-and-best-practices (7)

PPTX
Serverless Architectural Patterns
PPTX
Serverless Developer Experience I AWS Dev Day 2018
PDF
Serverless use cases with AWS Lambda
PDF
Genomics on aws-webinar-april2018
PDF
AWSomeDay Zurich 2018 - How to go serverless
PDF
Modern Applications Web Day | Impress Your Friends with Your First Serverless...
PDF
AWS Application Service Workshop - Serverless Architecture
Serverless Architectural Patterns
Serverless Developer Experience I AWS Dev Day 2018
Serverless use cases with AWS Lambda
Genomics on aws-webinar-april2018
AWSomeDay Zurich 2018 - How to go serverless
Modern Applications Web Day | Impress Your Friends with Your First Serverless...
AWS Application Service Workshop - Serverless Architecture
Ad

More from saifam (20)

PDF
1st year basic electronics
PDF
Engineering graphics
PDF
Basic civil &amp; mechanical engineering
DOCX
Surah al Fajr
PDF
Using encryption with_aws
PDF
Soc3 amazon web_services
PDF
Serverless architectures-with-aws-lambda
PDF
Security compute services_whitepaper
PDF
Lambda refarch-mobilebackend
PDF
Kms cryptographic-details
PDF
Kms cryptographic-details (1)
PDF
Gdpr compliance on_aws
PDF
D do s_white_paper_june2015
PDF
Cloud migration-main
PDF
Backup and recovery_approaches_using_aws
PDF
Aws web-hosting-best-practices
PDF
Aws security-pillar
PDF
Aws project jenkins-build-server
PDF
Aws well architected-framework
PDF
Aws rdbms oracle
1st year basic electronics
Engineering graphics
Basic civil &amp; mechanical engineering
Surah al Fajr
Using encryption with_aws
Soc3 amazon web_services
Serverless architectures-with-aws-lambda
Security compute services_whitepaper
Lambda refarch-mobilebackend
Kms cryptographic-details
Kms cryptographic-details (1)
Gdpr compliance on_aws
D do s_white_paper_june2015
Cloud migration-main
Backup and recovery_approaches_using_aws
Aws web-hosting-best-practices
Aws security-pillar
Aws project jenkins-build-server
Aws well architected-framework
Aws rdbms oracle
Ad

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
KodekX | Application Modernization Development
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Electronic commerce courselecture one. Pdf
PPTX
Cloud computing and distributed systems.
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
NewMind AI Monthly Chronicles - July 2025
Reach Out and Touch Someone: Haptics and Empathic Computing
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Review of recent advances in non-invasive hemoglobin estimation
KodekX | Application Modernization Development
Digital-Transformation-Roadmap-for-Companies.pptx
Understanding_Digital_Forensics_Presentation.pptx
Encapsulation_ Review paper, used for researhc scholars
CIFDAQ's Market Insight: SEC Turns Pro Crypto
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Network Security Unit 5.pdf for BCA BBA.
Electronic commerce courselecture one. Pdf
Cloud computing and distributed systems.

Serverless architecture-patterns-and-best-practices

  • 1. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Serverless Architecture Patterns And Best Practices Arun Gupta Principal Technologist argu@amazon.com @arungupta arun-gupta Adrian Hornsby Cloud Architecture Evangelist adhorn@amazon.com @adhorn adhorn
  • 2. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Agenda 1. Serverless Key Concepts 2. Lambda Basics 3. Lambda Best Practices 4. Serverless Application Model 5. CI/CD using CodeStar 6. Monitoring 7. Event Processing 8. Real-time Streaming
  • 3. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Serverless Key Concepts
  • 4. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. No servers to provision or manage Scales with usage Never pay for idle Availability and fault tolerance built in Serverless means…
  • 5. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Spectrum of AWS offerings AWS Lambda Amazon Kinesis Amazon S3 Amazon API Gateway Amazon SQS Amazon DynamoDB AWS IoT Amazon EMR Amazon ElastiCache Amazon RDS Amazon Redshift Amazon ES Managed Serverless Amazon EC2 Microsoft SQL Server “On EC2” Amazon Cognito Amazon CloudWatch
  • 6. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Lambda Basics
  • 7. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Using AWS Lambda Bring your own code • Node.js, Java, Python, C#, Go • Bring your own libraries (even native ones) Simple resource model • Select power rating from 128 MB to 3 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
  • 8. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Lambda execution model Synchronous (push) Asynchronous (event) Stream-based Amazon API Gateway AWS Lambda function Amazon DynamoDB Amazon SNS /api/hello AWS Lambda function Amazon S3 reqs Amazon Kinesis changes AWS Lambda service function
  • 9. © 2017, 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, etc.) public String handleRequest(Book book, Context context) { saveBook(book); return book.getName() + " saved!"; }
  • 10. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Lambda Best Practices
  • 11. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Lambda Best Practices • Separate the Lambda handler from core logic public class BookPostHandler implements RequestHandler<Book, String> { static DynamoDBMapper mapper = DDBUtil.getMapper(); public String handleRequest(Book book, Context context) { System.out.println("Adding book: " + book); saveBook(book); return book.getName() + " saved!"; } private void saveBook(Book book) { mapper.save(book); } }
  • 12. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Lambda Best Practices • Minimize package size to necessities <dependencies> <!-- https://mvnrepository.com/artifact/com.amazonaws/aws-lambda-java-core --> <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-lambda-java-core</artifactId> <version>1.1.0</version> </dependency> <!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-dynamodb --> <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-java-sdk-dynamodb</artifactId> <version>1.11.127</version> </dependency> </dependencies>
  • 13. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Lambda Best Practices • Use Environment Variables to modify operational behavior String region = System.getenv("AWS_REGION"); . . . String bucket = System.getenv(“S3_BUCKET”);
  • 14. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Lambda Best Practices • Self-contain dependencies in your function package <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.1.0</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> </execution> </executions> </plugin>
  • 15. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Lambda Best Practices • Leverage “Max Memory Used” to right-size your functions • Calculate 1000x all prime numbers < 1m Memory Compute time Cost 128 MB 11.722965 secs $0.024628 256 MB 6.678945 secs $0.028035 512 MB 3.194954 secs $0.026830 1024 MB 1.465984sec $0.024638 https://github.com/jconning/lambda-cpu-cost
  • 16. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Lambda Best Practices • Delete large unused functions (75GB limit per region)
  • 17. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Meet SAM!
  • 18. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Serverless Application Model CloudFormation extension optimized for serverless New serverless resource types: functions, APIs, and tables Supports anything CloudFormation supports Open specification (Apache 2.0) https://github.com/awslabs/serverless-application-model
  • 19. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. SAM Template AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Description: Simple CRUD webservice. Resources: GetFunction: Type: AWS::Serverless::Function Properties: Handler: org.sample.aws.samlocal.BookGetHandler Runtime: java8 CodeUri: ./target/sam-local-java-1.0-SNAPSHOT.jar Policies: AmazonDynamoDBReadOnlyAccess Timeout: 30 Environment: Variables: TABLE_NAME: !Ref Table Events: GetResource: Type: Api Properties: Path: /books Method: get Table: Type: AWS::Serverless::SimpleTable }
  • 20. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. SAM Commands Package Creates a deployment package (.zip file) Uploads deployment package to an S3 bucket Adds a CodeUri property with S3 URI Deploy Creates CloudFormation resources
  • 21. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. SAM Local • CLI for local testing of Serverless apps • Works with Lambda functions and “proxy style” APIs • Response object and function logs available on your local machine • Currently supports Java, Node.js and Python • Accepting PRs https://github.com/awslabs/aws-sam-local
  • 22. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. CI/CD using AWS CodeStar, AWS CodeBuild and AWS CodePipeline
  • 23. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Monitoring
  • 24. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS X-Ray Integration with Serverless • Lambda instruments incoming requests for all supported languages • Lambda runs the X-Ray daemon on all languages with an SDK var AWSXRay = require(‘aws-xray-sdk-core‘); AWSXRay.middleware.setSamplingRules(‘sampling-rules.json’); var AWS = AWSXRay.captureAWS(require(‘aws-sdk’)); S3Client = AWS.S3();
  • 25. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. X-Ray Trace Example
  • 26. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Event Processing
  • 27. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Event driven A B CEvent A on B triggers C Invocation Lambda functions Action
  • 28. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Event-driven platform S3 event notifications DynamoDB Streams Kinesis events Cognito events SNS events Custom events CloudTrail events LambdaDynamoDB Kinesis S3 Any custom Invoked in response to events - Changes in data - Changes in state Redshift SNS Access any service, including your own Such as… Lambda functions CloudWatch events
  • 29. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Event-driven actions Lambda: Resize Images Users upload photos S3: Source Bucket S3: Destination Bucket Triggered on PUTs
  • 30. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS Step Functions: Orchestrate a Serverless processing workflow using AWS Lambda
  • 31. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Real-time Streaming
  • 32. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 33. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. https://aws.amazon.com/solutions/case-studies/supercell/
  • 34. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Kinesis makes it easy to work with real-time streaming data Amazon Kinesis Streams • For Technical Developers • Collect and stream data for ordered, replay-able, real-time processing Amazon Kinesis Firehose • For all developers, data scientists • Easily load massive volumes of streaming data into Amazon S3, Redshift, ElasticSearch Amazon Kinesis Analytics • For all developers, data scientists • Easily analyze data streams using standard SQL queries
  • 35. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Producers Consumers Shard 1 Shard 2 Shard n Shard 3 … … Write: 1MB Read: 2MB ** A shard is a group of data records in a stream Amazon Kinesis
  • 36. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Processing a Kinesis Streams with AWS Lambda Shard 1 Shard 2 Shard 3 Shard 4 Shard n Kinesis Stream . . . . . . • Single instance of Lambda function per shard • Polls shard once per second • Lambda function instances created and removed automatically as stream is scaled Gets Records 1x per sec 10k records
  • 37. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Kinesis Analytics Use SQL to build real-time applications Easily write SQL code to process streaming data Connect to streaming source Continuously deliver SQL results
  • 40. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Further Reading Serverless Architectures with AWS Lambda https://d1.awsstatic.com/whitepapers/serverless-architectures-with-aws-lambda.pdf Optimizing Enterprise Economics with Serverless Architectures https://d0.awsstatic.com/whitepapers/optimizing-enterprise-economics-serverless-architectures.pdf Serverless Applications Lens - AWS Well-Architected Framework https://d1.awsstatic.com/whitepapers/architecture/AWS-Serverless-Applications-Lens.pdf Streaming Data Solutions on AWS with Amazon Kinesis https://d1.awsstatic.com/whitepapers/whitepaper-streaming-data-solutions-on-aws-with-amazon-kinesis.pdf AWS Serverless Multi-Tier Architectures https://d1.awsstatic.com/whitepapers/AWS_Serverless_Multi-Tier_Archiectures.pdf
  • 41. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. More info: https://aws.amazon.com/serverless/
  • 42. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Thank you!