SlideShare a Scribd company logo
Mike Apted
@mikeapted
Startup Solutions Architect
AWS Canada
Serverless Architectural Patterns
& Best Practices
Serverless Toronto Meetup
September 12th, 2019
Goal !!!!!!!!!!!!!!!!!!!
Homework
Serverless?
No servers to provision
or manage
Scales with usage
Never pay for idle Availability and fault
tolerance built in
#serverlessTO @mikeapted
Serverless?
#serverlessTO
@mikeapted
Operational responsibility models
On-Premises Cloud
Less More
Compute Virtual Machine
EC2 Elastic Beanstalk LambdaFargate
Databases MySQL MySQL on EC2
RDS MySQL RDS Aurora Aurora Serverless DynamoDB
Storage Storage
S3
Messaging ESBs
Amazon MQ Kinesis SQS / SNS
Analytics
Hadoop Hadoop on EC2 EMR Elasticsearch Service Athena
#serverlessTO @mikeapted
Operational responsibility models
On-Premises Cloud
Less More
Compute Virtual Machine
EC2 Elastic Beanstalk LambdaFargate
Databases MySQL MySQL on EC2
RDS MySQL RDS Aurora Aurora Serverless DynamoDB
Storage Storage
S3
Messaging ESBs
Amazon MQ Kinesis SQS / SNS
Analytics
Hadoop Hadoop on EC2 EMR Elasticsearch Service Athena
#serverlessTO @mikeapted
Serverless is an opera-onal model
AWS
Lambda
AWS
Fargate
Amazon
API Gateway
Amazon
SNS
Amazon
SQS
AWS
Step Functions
COMPUTE
DATA STORES
INTEGRATION
Amazon Aurora
Serverless
Amazon
S3
Amazon
DynamoDB
AWS
AppSync
#serverlessTO @mikeapted
Architecture Pa,erns
Web application
Internet/
other
services in
network
Amazon API
Gateway
AWS
Lambda
Amazon
DynamoDB
AWS Cloud
#serverlessTO @mikeapted
Web applica*on
Internet/
other
services in
network
Amazon API
Gateway
AWS
Lambda
Amazon
Aurora
Serverless
AWS Cloud
#serverlessTO @mikeapted
Microservices
Internet/
other
services in
network
Amazon API
Gateway
AWS
Lambda
Amazon
DynamoDB
AWS Cloud
#serverlessTO @mikeapted
Amazon Aurora
Serverless
Microservice patterns: Lambda API
1. Lambda directly
invoked via invoke API
SDK clients
API provided by the Lambda service
Used by all other services that invoke
Lambda across all models
Supports sync and async
Can pass any event payload structure you
want
Client included in every SDK
Synchronous / Asynchronous
Lambda
function
#serverlessTO @mikeapted
Lambda Execu,on Model
Synchronous (push) Asynchronous (event) Stream
(poll-based)
Amazon
DynamoDB
Amazon
SNS
/order
Amazon
S3
reqs
Amazon Kinesis
Data Streams
changes
AWS Lambda
service
function
Amazon API
Gateway
Lambda
function
Lambda
function
Microservice pa,erns: Amazon SNS + Lambda
2. Lambda function(s) invoked
Amazon
SNS topic
1. Data published to a topic
Data
Simple, flexible, fully managed
publish/subscribe messaging and mobile
push notification service for high
throughput, highly reliable message delivery
Messages are published to a topic
Topics can have multiple subscribers (fanout)
Messages can be filtered and only sent to
certain subscribers
Asynchronous
Lambda
function
Lambda
function
#serverlessTO @mikeapted
Microservice patterns: Amazon SQS + Lambda
1. Message
inserted into
a queue
Message
Amazon
SQS3. SQS removes
message from
queue on
successful
response from
function
2. Lambda
function invoked
Simple, flexible, fully managed message
queuing service for reliably and
continuously exchanging any volume of
messages from anywhere
Processed in batches
At-least-once delivery
Visibility timeout allows for handling of
failures during processing
Asynchronous
Lambda
function
#serverlessTO @mikeapted
Streaming Data: Transformation
Record
producers
AWS
Lambda
AWS Cloud
Amazon Kinesis
Data Firehose
Amazon
S3
Amazon
Redshift
Amazon
Elasticsearch
#serverlessTO @mikeapted
Streaming Data: Enrichment
Record
producers
AWS
Lambda
Amazon
DynamoDB
AWS Cloud
Amazon Kinesis
Data Firehose
Amazon
S3
Amazon
Redshift
Amazon
Elasticsearch
#serverlessTO @mikeapted
Streaming Data: Fan Out
Record
producers
AWS Cloud
Amazon Kinesis
Data Streams
AWS
Lambda
#serverlessTO @mikeapted
Streaming Data: Real Time Analy2cs
Record
producers
AWS Cloud
Amazon Kinesis
Data Streams
Amazon Kinesis
Data Analytics
AWS
Lambda
#serverlessTO @mikeapted
Data Lakes: Batch Processing (MapReduce)
Amazon
S3
AWS
Lambda
Amazon
DynamoDB
AWS Cloud
#serverlessTO @mikeapted
Orchestra)on: Step Func)ons
Serverless workflow management
with zero administration
• Makes it easy to coordinate the
components of distributed applications
and microservices using visual workflows
• Automatically triggers and tracks each
step and retries when there are errors, so
your application executes in order and as
expected
• Logs the state of each step, so when
things do go wrong, you can diagnose and
debug problems quickly
#serverlessTO @mikeapted
Orchestra)on: Step Func)ons
With serverless polling With direct service integrationStart
End
AWS
Lambda
functions
Start
End
No
Lambda
functions
#serverlessTO @mikeapted
Best Prac*ces
DevOps: Tes*ng
• Decouple business logic from your Lambda handler
• Write unit tests as you normally would
• Leverage tools like “aws-sdk-mock”
• Leverage a framework for easier local testing
• i.e. SAM Local
• For integration tests leverage real services
DevOps: Deployments + Frameworks
• Build pipelines from source control to production
• Consider one pipeline per service
• Leverage capabilities that are built into frameworks like:
• traffic shifting between Lambda aliases
• canary or blue/green deployments
• error monitoring
• automatic rollbacks,
DevOps: Share Code w/ Lambda Layers
Lets functions easily share code: Upload layer
once, reference within any function
Layer can be anything: dependencies, training
data, configuration files, etc
Promote separation of responsibilities, lets
developers iterate faster on writing business
logic
Built in support for secure sharing by
ecosystem
#serverlessTO @mikeapted
Observability: X-Ray
• 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();
#serverlessTO @mikeapted
Observability: X-Ray
#serverlessTO @mikeapted
Observability: X-Ray
#serverlessTO @mikeapted
Observability: Metrics
• 6 Built in metrics for Lambda
• Invocation Count, Invocation duration,
Invocation errors, Throttled Invocation, Iterator
Age, DLQ Errors
• Can call “put-metric-data” from your function
code for custom metrics
• 7 Built in metrics for API-Gateway
• API Calls Count, Latency, 4XXs, 5XXs, Integration
Latency, Cache Hit Count, Cache Miss Count
• Error and Cache metrics now support averages
and percen,les
#serverlessTO @mikeapted
Observability: Logs
• API Gateway Logging
• 2 Levels of logging, ERROR and INFO
• Optionally log method request/body content
• Set globally in stage, or override per method
• Lambda Logging
• Logging directly from your code with your
language’s equivalent of console.log()
• Basic request information included
• Log Pivots
• Build metrics based on log filters
• Jump to logs that generated metrics
• Export logs to AWS ElastiCache or S3
• Explore with Kibana or Athena/QuickSight
#serverlessTO @mikeapted
Observability: DLQ
“By default, a failed Lambda function invoked
asynchronously is retried twice, and then the event is
discarded.”
https://docs.aws.amazon.com/lambda/latest/dg/dlq.html
• Turn this on! (for async use-cases)
• Monitor it via an SQS Queue length metric/alarm
• If you use SNS, send the messages to something durable
and/or a trusted endpoint for processing
• If and when things fail DLQ can save your invocation event
information
☠
✉
Q
#serverlessTO @mikeapted
Performance: Function Lifecycle
Bootstrap
the runtime
Start your
code
Full
cold start
Partial
cold start
Warm
start
Download
your code
Start new
Execution
environment
AWS optimization Your optimization
#serverlessTO @mikeapted
Anatomy of a Lambda functionImport sdk
Import http-lib
Import ham-sandwich
Pre-handler-secret-getter()
Pre-handler-db-connect()
Function myhandler(event, context) {
<Event handling logic> {
result = SubfunctionA()
}else {
result = SubfunctionB()
return result;
}
Function Pre-handler-secret-getter() {
}
Function Pre-handler-db-connect(){
}
Function subFunctionA(thing){
## logic here
}
Function subFunctionB(thing){
## logic here
}
Anatomy of a Lambda functionImport sdk
Import http-lib
Import ham-sandwich
Pre-handler-secret-getter()
Pre-handler-db-connect()
Function myhandler(event, context) {
<Event handling logic> {
result = SubfunctionA()
}else {
result = SubfunctionB()
return result;
}
Function Pre-handler-secret-getter() {
}
Function Pre-handler-db-connect(){
}
Function subFunctionA(thing){
## logic here
}
Function subFunctionB(thing){
## logic here
}
Dependencies, configuration information, common helper functions
Common helper functions
Business logic sub-functions
Your handler
Performance: Cold Starts / VPC to VPC NAT
Faster
Scaling
Lower
Latency
Easier To
Use
Performance: Resource Alloca1on
Lambda exposes only a memory control, with the % of CPU
core and network capacity allocated to a function
proportionally
#serverlessTO @mikeapted
Performance: Resource Alloca1on
#serverlessTO @mikeapted
Performance: Mul/threading
• <1.8GB is still single core
• CPU bound workloads won’t see gains – processes share
same resources
• >1.8GB is multi core
• CPU bound workloads will gains, but need to multi thread
• I/O bound workloads WILL likely see gains
• e.g. parallel calculations to return
#serverlessTO @mikeapted
Security: Configura1on
• 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)
#serverlessTO @mikeapted
Security: Secrets
AWS Parameter Store
Centralized store to manage your
configuration data
• Supports hierarchies
• Plain-text or encrypted with KMS
• Can send notifications of changes to Amazon
SNS/ AWS Lambda
• Can be secured with IAM
• Calls recorded in CloudTrail
• Can be tagged
• Integrated with AWS Secrets Manager
• Available via API/SDK
Useful for: centralized environment
variables, secrets control, feature
flags
from __future__ import print_function
import json
import boto3
ssm = boto3.client('ssm', 'us-east-1')
def get_parameters():
response = ssm.get_parameters(
Names=['LambdaSecureString'],WithDec
ryption=True
)
for parameter in response['Parameters']:
return parameter['Value']
def lambda_handler(event, context):
value = get_parameters()
print("value1 = " + value)
return value # Echo back the first key
value
Security: Permissions
Function policies:
• “Actions on bucket X can invoke
Lambda function Z"
• Resource policies allow for cross
account access
Execution role:
• “Lambda function A can read
from DynamoDB table users”
• Define what AWS resources/API
calls can this function access via
IAM
Event source ServicesFunction
#serverlessTO @mikeapted
aws.amazon.com/serverless
#serverlessTO @mikeapted
serverless-stack.com
#serverlessTO @mikeapted
Mike Apted
@mikeapted
“No server is easier to
manage than no server.” -
Werner Vogels, Amazon
CTO

More Related Content

Similar to Serverless Architectural Patterns & Best Practices (20)

PPTX
Primeros pasos en desarrollo serverless
javier ramirez
 
PDF
Serveless design patterns (VoxxedDays Luxembourg)
Yan Cui
 
PDF
Jumpstart your idea with AWS Serverless [Oct 2020]
Dhaval Nagar
 
PDF
2022 Presentation | Serverless Innovation with AWS
Dhaval Nagar
 
PDF
Serveless Design Patterns (Serverless Computing London)
Yan Cui
 
PDF
Serverless AWS reInvent 2019 recap
Daniel Zivkovic
 
PDF
Serverless Meetup - Event Sourcing
Luca Bianchi
 
PDF
NDev Talk - Serverless Design Patterns
Ryan Green
 
PDF
Experiences in Architecting & Implementing Platforms using Serverless.pdf
Srushith Repakula
 
PDF
Introduction to Serverless through Architectural Patterns
Mathieu Mailhos
 
PDF
Serverless use cases with AWS Lambda - More Serverless Event
Boaz Ziniman
 
PDF
Serverless Event Sourcing
Luca Bianchi
 
PDF
Modern Applications Development on AWS
Boaz Ziniman
 
PPTX
AWS Startup Day - Boston 2018 - The Best Practices and Hard Lessons Learned o...
Chris Munns
 
PDF
Serverless use cases with AWS Lambda
Boaz Ziniman
 
PDF
Serverless: Beyond Lambda Functions (V2)
Srushith Repakula
 
PPTX
Getting Started with Serverless Architectures
AWS Summits
 
PPTX
Serverless architectures: APIs, Serverless Functions, Microservices - How to ...
Bala Subra
 
PDF
Introduction to Serverless
Steven Bryen
 
PPTX
Going Serverless with AWS Lambda at ReportGarden
Jay Gandhi
 
Primeros pasos en desarrollo serverless
javier ramirez
 
Serveless design patterns (VoxxedDays Luxembourg)
Yan Cui
 
Jumpstart your idea with AWS Serverless [Oct 2020]
Dhaval Nagar
 
2022 Presentation | Serverless Innovation with AWS
Dhaval Nagar
 
Serveless Design Patterns (Serverless Computing London)
Yan Cui
 
Serverless AWS reInvent 2019 recap
Daniel Zivkovic
 
Serverless Meetup - Event Sourcing
Luca Bianchi
 
NDev Talk - Serverless Design Patterns
Ryan Green
 
Experiences in Architecting & Implementing Platforms using Serverless.pdf
Srushith Repakula
 
Introduction to Serverless through Architectural Patterns
Mathieu Mailhos
 
Serverless use cases with AWS Lambda - More Serverless Event
Boaz Ziniman
 
Serverless Event Sourcing
Luca Bianchi
 
Modern Applications Development on AWS
Boaz Ziniman
 
AWS Startup Day - Boston 2018 - The Best Practices and Hard Lessons Learned o...
Chris Munns
 
Serverless use cases with AWS Lambda
Boaz Ziniman
 
Serverless: Beyond Lambda Functions (V2)
Srushith Repakula
 
Getting Started with Serverless Architectures
AWS Summits
 
Serverless architectures: APIs, Serverless Functions, Microservices - How to ...
Bala Subra
 
Introduction to Serverless
Steven Bryen
 
Going Serverless with AWS Lambda at ReportGarden
Jay Gandhi
 

More from Daniel Zivkovic (20)

PDF
'The Art & Science of LLM Reliability - Building Trustworthy AI Systems' by M...
Daniel Zivkovic
 
PDF
AI - Your Startup Sidekick (Leveraging AI to Bootstrap a Lean Startup).pdf
Daniel Zivkovic
 
PDF
All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...
Daniel Zivkovic
 
PDF
Canadian Experts Discuss Modern Data Stacks and Cloud Computing for 5 Years o...
Daniel Zivkovic
 
PDF
Opinionated re:Invent recap with AWS Heroes & Builders
Daniel Zivkovic
 
PDF
Google Cloud Next '22 Recap: Serverless & Data edition
Daniel Zivkovic
 
PDF
Conversational Document Processing AI with Rui Costa
Daniel Zivkovic
 
PDF
How to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
Daniel Zivkovic
 
PDF
Gojko's 5 rules for super responsive Serverless applications
Daniel Zivkovic
 
PDF
Retail Analytics and BI with Looker, BigQuery, GCP & Leigha Jarett
Daniel Zivkovic
 
PDF
What's new in Serverless at AWS?
Daniel Zivkovic
 
PDF
Intro to Vertex AI, unified MLOps platform for Data Scientists & ML Engineers
Daniel Zivkovic
 
PDF
Empowering Developers to be Healthcare Heroes
Daniel Zivkovic
 
PDF
Get started with Dialogflow & Contact Center AI on Google Cloud
Daniel Zivkovic
 
PDF
Building a Data Cloud to enable Analytics & AI-Driven Innovation - Lak Lakshm...
Daniel Zivkovic
 
PDF
Smart Cities of Italy: Integrating the Cyber World with the IoT
Daniel Zivkovic
 
PDF
Running Business Analytics for a Serverless Insurance Company - Joe Emison & ...
Daniel Zivkovic
 
PDF
This is my Architecture to prevent Cloud Bill Shock
Daniel Zivkovic
 
PDF
Lunch & Learn BigQuery & Firebase from other Google Cloud customers
Daniel Zivkovic
 
PDF
Azure for AWS & GCP Pros: Which Azure services to use?
Daniel Zivkovic
 
'The Art & Science of LLM Reliability - Building Trustworthy AI Systems' by M...
Daniel Zivkovic
 
AI - Your Startup Sidekick (Leveraging AI to Bootstrap a Lean Startup).pdf
Daniel Zivkovic
 
All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...
Daniel Zivkovic
 
Canadian Experts Discuss Modern Data Stacks and Cloud Computing for 5 Years o...
Daniel Zivkovic
 
Opinionated re:Invent recap with AWS Heroes & Builders
Daniel Zivkovic
 
Google Cloud Next '22 Recap: Serverless & Data edition
Daniel Zivkovic
 
Conversational Document Processing AI with Rui Costa
Daniel Zivkovic
 
How to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
Daniel Zivkovic
 
Gojko's 5 rules for super responsive Serverless applications
Daniel Zivkovic
 
Retail Analytics and BI with Looker, BigQuery, GCP & Leigha Jarett
Daniel Zivkovic
 
What's new in Serverless at AWS?
Daniel Zivkovic
 
Intro to Vertex AI, unified MLOps platform for Data Scientists & ML Engineers
Daniel Zivkovic
 
Empowering Developers to be Healthcare Heroes
Daniel Zivkovic
 
Get started with Dialogflow & Contact Center AI on Google Cloud
Daniel Zivkovic
 
Building a Data Cloud to enable Analytics & AI-Driven Innovation - Lak Lakshm...
Daniel Zivkovic
 
Smart Cities of Italy: Integrating the Cyber World with the IoT
Daniel Zivkovic
 
Running Business Analytics for a Serverless Insurance Company - Joe Emison & ...
Daniel Zivkovic
 
This is my Architecture to prevent Cloud Bill Shock
Daniel Zivkovic
 
Lunch & Learn BigQuery & Firebase from other Google Cloud customers
Daniel Zivkovic
 
Azure for AWS & GCP Pros: Which Azure services to use?
Daniel Zivkovic
 
Ad

Recently uploaded (20)

PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PDF
Online Queue Management System for Public Service Offices in Nepal [Focused i...
Rishab Acharya
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPTX
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Human Resources Information System (HRIS)
Amity University, Patna
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
Online Queue Management System for Public Service Offices in Nepal [Focused i...
Rishab Acharya
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
Ad

Serverless Architectural Patterns & Best Practices

  • 1. Mike Apted @mikeapted Startup Solutions Architect AWS Canada Serverless Architectural Patterns & Best Practices Serverless Toronto Meetup September 12th, 2019
  • 4. Serverless? No servers to provision or manage Scales with usage Never pay for idle Availability and fault tolerance built in #serverlessTO @mikeapted
  • 6. Operational responsibility models On-Premises Cloud Less More Compute Virtual Machine EC2 Elastic Beanstalk LambdaFargate Databases MySQL MySQL on EC2 RDS MySQL RDS Aurora Aurora Serverless DynamoDB Storage Storage S3 Messaging ESBs Amazon MQ Kinesis SQS / SNS Analytics Hadoop Hadoop on EC2 EMR Elasticsearch Service Athena #serverlessTO @mikeapted
  • 7. Operational responsibility models On-Premises Cloud Less More Compute Virtual Machine EC2 Elastic Beanstalk LambdaFargate Databases MySQL MySQL on EC2 RDS MySQL RDS Aurora Aurora Serverless DynamoDB Storage Storage S3 Messaging ESBs Amazon MQ Kinesis SQS / SNS Analytics Hadoop Hadoop on EC2 EMR Elasticsearch Service Athena #serverlessTO @mikeapted
  • 8. Serverless is an opera-onal model AWS Lambda AWS Fargate Amazon API Gateway Amazon SNS Amazon SQS AWS Step Functions COMPUTE DATA STORES INTEGRATION Amazon Aurora Serverless Amazon S3 Amazon DynamoDB AWS AppSync #serverlessTO @mikeapted
  • 10. Web application Internet/ other services in network Amazon API Gateway AWS Lambda Amazon DynamoDB AWS Cloud #serverlessTO @mikeapted
  • 11. Web applica*on Internet/ other services in network Amazon API Gateway AWS Lambda Amazon Aurora Serverless AWS Cloud #serverlessTO @mikeapted
  • 13. Microservice patterns: Lambda API 1. Lambda directly invoked via invoke API SDK clients API provided by the Lambda service Used by all other services that invoke Lambda across all models Supports sync and async Can pass any event payload structure you want Client included in every SDK Synchronous / Asynchronous Lambda function #serverlessTO @mikeapted
  • 14. Lambda Execu,on Model Synchronous (push) Asynchronous (event) Stream (poll-based) Amazon DynamoDB Amazon SNS /order Amazon S3 reqs Amazon Kinesis Data Streams changes AWS Lambda service function Amazon API Gateway Lambda function Lambda function
  • 15. Microservice pa,erns: Amazon SNS + Lambda 2. Lambda function(s) invoked Amazon SNS topic 1. Data published to a topic Data Simple, flexible, fully managed publish/subscribe messaging and mobile push notification service for high throughput, highly reliable message delivery Messages are published to a topic Topics can have multiple subscribers (fanout) Messages can be filtered and only sent to certain subscribers Asynchronous Lambda function Lambda function #serverlessTO @mikeapted
  • 16. Microservice patterns: Amazon SQS + Lambda 1. Message inserted into a queue Message Amazon SQS3. SQS removes message from queue on successful response from function 2. Lambda function invoked Simple, flexible, fully managed message queuing service for reliably and continuously exchanging any volume of messages from anywhere Processed in batches At-least-once delivery Visibility timeout allows for handling of failures during processing Asynchronous Lambda function #serverlessTO @mikeapted
  • 17. Streaming Data: Transformation Record producers AWS Lambda AWS Cloud Amazon Kinesis Data Firehose Amazon S3 Amazon Redshift Amazon Elasticsearch #serverlessTO @mikeapted
  • 18. Streaming Data: Enrichment Record producers AWS Lambda Amazon DynamoDB AWS Cloud Amazon Kinesis Data Firehose Amazon S3 Amazon Redshift Amazon Elasticsearch #serverlessTO @mikeapted
  • 19. Streaming Data: Fan Out Record producers AWS Cloud Amazon Kinesis Data Streams AWS Lambda #serverlessTO @mikeapted
  • 20. Streaming Data: Real Time Analy2cs Record producers AWS Cloud Amazon Kinesis Data Streams Amazon Kinesis Data Analytics AWS Lambda #serverlessTO @mikeapted
  • 21. Data Lakes: Batch Processing (MapReduce) Amazon S3 AWS Lambda Amazon DynamoDB AWS Cloud #serverlessTO @mikeapted
  • 22. Orchestra)on: Step Func)ons Serverless workflow management with zero administration • Makes it easy to coordinate the components of distributed applications and microservices using visual workflows • Automatically triggers and tracks each step and retries when there are errors, so your application executes in order and as expected • Logs the state of each step, so when things do go wrong, you can diagnose and debug problems quickly #serverlessTO @mikeapted
  • 23. Orchestra)on: Step Func)ons With serverless polling With direct service integrationStart End AWS Lambda functions Start End No Lambda functions #serverlessTO @mikeapted
  • 25. DevOps: Tes*ng • Decouple business logic from your Lambda handler • Write unit tests as you normally would • Leverage tools like “aws-sdk-mock” • Leverage a framework for easier local testing • i.e. SAM Local • For integration tests leverage real services
  • 26. DevOps: Deployments + Frameworks • Build pipelines from source control to production • Consider one pipeline per service • Leverage capabilities that are built into frameworks like: • traffic shifting between Lambda aliases • canary or blue/green deployments • error monitoring • automatic rollbacks,
  • 27. DevOps: Share Code w/ Lambda Layers Lets functions easily share code: Upload layer once, reference within any function Layer can be anything: dependencies, training data, configuration files, etc Promote separation of responsibilities, lets developers iterate faster on writing business logic Built in support for secure sharing by ecosystem #serverlessTO @mikeapted
  • 28. Observability: X-Ray • 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(); #serverlessTO @mikeapted
  • 31. Observability: Metrics • 6 Built in metrics for Lambda • Invocation Count, Invocation duration, Invocation errors, Throttled Invocation, Iterator Age, DLQ Errors • Can call “put-metric-data” from your function code for custom metrics • 7 Built in metrics for API-Gateway • API Calls Count, Latency, 4XXs, 5XXs, Integration Latency, Cache Hit Count, Cache Miss Count • Error and Cache metrics now support averages and percen,les #serverlessTO @mikeapted
  • 32. Observability: Logs • API Gateway Logging • 2 Levels of logging, ERROR and INFO • Optionally log method request/body content • Set globally in stage, or override per method • Lambda Logging • Logging directly from your code with your language’s equivalent of console.log() • Basic request information included • Log Pivots • Build metrics based on log filters • Jump to logs that generated metrics • Export logs to AWS ElastiCache or S3 • Explore with Kibana or Athena/QuickSight #serverlessTO @mikeapted
  • 33. Observability: DLQ “By default, a failed Lambda function invoked asynchronously is retried twice, and then the event is discarded.” https://docs.aws.amazon.com/lambda/latest/dg/dlq.html • Turn this on! (for async use-cases) • Monitor it via an SQS Queue length metric/alarm • If you use SNS, send the messages to something durable and/or a trusted endpoint for processing • If and when things fail DLQ can save your invocation event information ☠ ✉ Q #serverlessTO @mikeapted
  • 34. Performance: Function Lifecycle Bootstrap the runtime Start your code Full cold start Partial cold start Warm start Download your code Start new Execution environment AWS optimization Your optimization #serverlessTO @mikeapted
  • 35. Anatomy of a Lambda functionImport sdk Import http-lib Import ham-sandwich Pre-handler-secret-getter() Pre-handler-db-connect() Function myhandler(event, context) { <Event handling logic> { result = SubfunctionA() }else { result = SubfunctionB() return result; } Function Pre-handler-secret-getter() { } Function Pre-handler-db-connect(){ } Function subFunctionA(thing){ ## logic here } Function subFunctionB(thing){ ## logic here }
  • 36. Anatomy of a Lambda functionImport sdk Import http-lib Import ham-sandwich Pre-handler-secret-getter() Pre-handler-db-connect() Function myhandler(event, context) { <Event handling logic> { result = SubfunctionA() }else { result = SubfunctionB() return result; } Function Pre-handler-secret-getter() { } Function Pre-handler-db-connect(){ } Function subFunctionA(thing){ ## logic here } Function subFunctionB(thing){ ## logic here } Dependencies, configuration information, common helper functions Common helper functions Business logic sub-functions Your handler
  • 37. Performance: Cold Starts / VPC to VPC NAT Faster Scaling Lower Latency Easier To Use
  • 38. Performance: Resource Alloca1on Lambda exposes only a memory control, with the % of CPU core and network capacity allocated to a function proportionally #serverlessTO @mikeapted
  • 40. Performance: Mul/threading • <1.8GB is still single core • CPU bound workloads won’t see gains – processes share same resources • >1.8GB is multi core • CPU bound workloads will gains, but need to multi thread • I/O bound workloads WILL likely see gains • e.g. parallel calculations to return #serverlessTO @mikeapted
  • 41. Security: Configura1on • 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) #serverlessTO @mikeapted
  • 42. Security: Secrets AWS Parameter Store Centralized store to manage your configuration data • Supports hierarchies • Plain-text or encrypted with KMS • Can send notifications of changes to Amazon SNS/ AWS Lambda • Can be secured with IAM • Calls recorded in CloudTrail • Can be tagged • Integrated with AWS Secrets Manager • Available via API/SDK Useful for: centralized environment variables, secrets control, feature flags from __future__ import print_function import json import boto3 ssm = boto3.client('ssm', 'us-east-1') def get_parameters(): response = ssm.get_parameters( Names=['LambdaSecureString'],WithDec ryption=True ) for parameter in response['Parameters']: return parameter['Value'] def lambda_handler(event, context): value = get_parameters() print("value1 = " + value) return value # Echo back the first key value
  • 43. Security: Permissions Function policies: • “Actions on bucket X can invoke Lambda function Z" • Resource policies allow for cross account access Execution role: • “Lambda function A can read from DynamoDB table users” • Define what AWS resources/API calls can this function access via IAM Event source ServicesFunction #serverlessTO @mikeapted
  • 46. Mike Apted @mikeapted “No server is easier to manage than no server.” - Werner Vogels, Amazon CTO