SlideShare una empresa de Scribd logo
1 de 46
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

以Device Shadows與Rules Engine串聯實體世界
以Device Shadows與Rules Engine串聯實體世界以Device Shadows與Rules Engine串聯實體世界
以Device Shadows與Rules Engine串聯實體世界
 
Deep Dive on Microservices and Amazon ECS
Deep Dive on Microservices and Amazon ECSDeep Dive on Microservices and Amazon ECS
Deep Dive on Microservices and Amazon ECS
 
Getting Started with Serverless and Container Architectures
Getting Started with Serverless and Container ArchitecturesGetting Started with Serverless and Container Architectures
Getting Started with Serverless and Container Architectures
 
AWS re:Invent 2016: All Your Chats are Belong to Bots: Building a Serverless ...
AWS re:Invent 2016: All Your Chats are Belong to Bots: Building a Serverless ...AWS re:Invent 2016: All Your Chats are Belong to Bots: Building a Serverless ...
AWS re:Invent 2016: All Your Chats are Belong to Bots: Building a Serverless ...
 
AWS Meet-up: Logging At Scale on AWS
AWS Meet-up: Logging At Scale on AWSAWS Meet-up: Logging At Scale on AWS
AWS Meet-up: Logging At Scale on AWS
 
AWS re:Invent 2016: Securing Serverless Architectures, and API Filtering at L...
AWS re:Invent 2016: Securing Serverless Architectures, and API Filtering at L...AWS re:Invent 2016: Securing Serverless Architectures, and API Filtering at L...
AWS re:Invent 2016: Securing Serverless Architectures, and API Filtering at L...
 
AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)
AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)
AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)
 
AWS re:Invent 2016: What’s New with AWS Lambda (SVR202)
AWS re:Invent 2016: What’s New with AWS Lambda (SVR202)AWS re:Invent 2016: What’s New with AWS Lambda (SVR202)
AWS re:Invent 2016: What’s New with AWS Lambda (SVR202)
 
Streaming analytics on Google Cloud Platform, by Javier Ramirez, teowaki
Streaming analytics on Google Cloud Platform, by Javier Ramirez, teowakiStreaming analytics on Google Cloud Platform, by Javier Ramirez, teowaki
Streaming analytics on Google Cloud Platform, by Javier Ramirez, teowaki
 
Serverless computing with AWS Lambda
Serverless computing with AWS Lambda Serverless computing with AWS Lambda
Serverless computing with AWS Lambda
 
Getting Started with Serverless Architectures
Getting Started with Serverless ArchitecturesGetting Started with Serverless Architectures
Getting Started with Serverless Architectures
 
AWS Lambda and the Serverless Cloud
AWS Lambda and the Serverless CloudAWS Lambda and the Serverless Cloud
AWS Lambda and the Serverless Cloud
 
10 Tips For Serverless Backends With NodeJS and AWS Lambda
10 Tips For Serverless Backends With NodeJS and AWS Lambda10 Tips For Serverless Backends With NodeJS and AWS Lambda
10 Tips For Serverless Backends With NodeJS and AWS Lambda
 
Top conf serverlezz
Top conf   serverlezzTop conf   serverlezz
Top conf serverlezz
 
AWS re:Invent 2016: Serverless Architectural Patterns and Best Practices (ARC...
AWS re:Invent 2016: Serverless Architectural Patterns and Best Practices (ARC...AWS re:Invent 2016: Serverless Architectural Patterns and Best Practices (ARC...
AWS re:Invent 2016: Serverless Architectural Patterns and Best Practices (ARC...
 
Building a WorkFlow using AWS Step Functions with Skycatch
Building a WorkFlow using AWS Step Functions with SkycatchBuilding a WorkFlow using AWS Step Functions with Skycatch
Building a WorkFlow using AWS Step Functions with Skycatch
 
AWS Lambda in C#
AWS Lambda in C#AWS Lambda in C#
AWS Lambda in C#
 
Serverless by Example: Building a Real-Time Chat System
Serverless by Example: Building a Real-Time Chat SystemServerless by Example: Building a Real-Time Chat System
Serverless by Example: Building a Real-Time Chat System
 
Intro to Batch Processing on AWS - DevDay Los Angeles 2017
Intro to Batch Processing on AWS - DevDay Los Angeles 2017Intro to Batch Processing on AWS - DevDay Los Angeles 2017
Intro to Batch Processing on AWS - DevDay Los Angeles 2017
 
使用 Serverless 技術打造支援 Alexa 的物聯網服務
使用 Serverless 技術打造支援 Alexa 的物聯網服務使用 Serverless 技術打造支援 Alexa 的物聯網服務
使用 Serverless 技術打造支援 Alexa 的物聯網服務
 

Similar a Serverless Architectural Patterns & Best Practices

Track 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptx
Track 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptxTrack 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptx
Track 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptx
Amazon Web Services
 

Similar a Serverless Architectural Patterns & Best Practices (20)

AWS re:Invent 2016: ↑↑↓↓←→←→ BA Lambda Start (SVR305)
AWS re:Invent 2016: ↑↑↓↓←→←→ BA Lambda Start (SVR305)AWS re:Invent 2016: ↑↑↓↓←→←→ BA Lambda Start (SVR305)
AWS re:Invent 2016: ↑↑↓↓←→←→ BA Lambda Start (SVR305)
 
Compute Without Servers – Building Applications with AWS Lambda
Compute Without Servers – Building Applications with AWS LambdaCompute Without Servers – Building Applications with AWS Lambda
Compute Without Servers – Building Applications with AWS Lambda
 
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
 
Migrating your .NET Applications to the AWS Serverless Platform
Migrating your .NET Applications to the AWS Serverless PlatformMigrating your .NET Applications to the AWS Serverless Platform
Migrating your .NET Applications to the AWS Serverless Platform
 
Serverless Architectural Patterns
Serverless Architectural PatternsServerless Architectural Patterns
Serverless Architectural Patterns
 
Big data and serverless - AWS UG The Netherlands
Big data and serverless - AWS UG The NetherlandsBig data and serverless - AWS UG The Netherlands
Big data and serverless - AWS UG The Netherlands
 
Getting Started with AWS Lambda and the Serverless Cloud
Getting Started with AWS Lambda and the Serverless CloudGetting Started with AWS Lambda and the Serverless Cloud
Getting Started with AWS Lambda and the Serverless Cloud
 
Track 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptx
Track 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptxTrack 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptx
Track 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptx
 
Getting Started with AWS Lambda and the Serverless Cloud
Getting Started with AWS Lambda and the Serverless CloudGetting Started with AWS Lambda and the Serverless Cloud
Getting Started with AWS Lambda and the Serverless Cloud
 
re:Invent ARC307 - Serverless architectural patterns and best practices.pdf
re:Invent ARC307 - Serverless architectural patterns and best practices.pdfre:Invent ARC307 - Serverless architectural patterns and best practices.pdf
re:Invent ARC307 - Serverless architectural patterns and best practices.pdf
 
Serverless cat detector workshop - cloudyna 2017 (16.12.2017)
Serverless cat detector   workshop - cloudyna 2017 (16.12.2017)Serverless cat detector   workshop - cloudyna 2017 (16.12.2017)
Serverless cat detector workshop - cloudyna 2017 (16.12.2017)
 
Getting Started with AWS Lambda and the Serverless Cloud
Getting Started with AWS Lambda and the Serverless CloudGetting Started with AWS Lambda and the Serverless Cloud
Getting Started with AWS Lambda and the Serverless Cloud
 
AWS October Webinar Series - AWS Lambda Best Practices: Python, Scheduled Job...
AWS October Webinar Series - AWS Lambda Best Practices: Python, Scheduled Job...AWS October Webinar Series - AWS Lambda Best Practices: Python, Scheduled Job...
AWS October Webinar Series - AWS Lambda Best Practices: Python, Scheduled Job...
 
Building a serverless company on AWS lambda and Serverless framework
Building a serverless company on AWS lambda and Serverless frameworkBuilding a serverless company on AWS lambda and Serverless framework
Building a serverless company on AWS lambda and Serverless framework
 
SMC303 Real-time Data Processing Using AWS Lambda
SMC303 Real-time Data Processing Using AWS LambdaSMC303 Real-time Data Processing Using AWS Lambda
SMC303 Real-time Data Processing Using AWS Lambda
 
AWS re:Invent 2016 Day 2 Keynote re:Cap
AWS re:Invent 2016 Day 2 Keynote re:CapAWS re:Invent 2016 Day 2 Keynote re:Cap
AWS re:Invent 2016 Day 2 Keynote re:Cap
 
AWS re:Invent 2016 Day 2 Keynote re:Cap
AWS re:Invent 2016 Day 2 Keynote re:CapAWS re:Invent 2016 Day 2 Keynote re:Cap
AWS re:Invent 2016 Day 2 Keynote re:Cap
 
Aws Lambda in Swift - NSLondon - 3rd December 2020
Aws Lambda in Swift - NSLondon - 3rd December 2020Aws Lambda in Swift - NSLondon - 3rd December 2020
Aws Lambda in Swift - NSLondon - 3rd December 2020
 
Building a Real Time Dashboard with Amazon Kinesis, Amazon Lambda and Amazon ...
Building a Real Time Dashboard with Amazon Kinesis, Amazon Lambda and Amazon ...Building a Real Time Dashboard with Amazon Kinesis, Amazon Lambda and Amazon ...
Building a Real Time Dashboard with Amazon Kinesis, Amazon Lambda and Amazon ...
 
Intro To Serverless Application Architecture: Collision 2018
Intro To Serverless Application Architecture: Collision 2018Intro To Serverless Application Architecture: Collision 2018
Intro To Serverless Application Architecture: Collision 2018
 

Más de Daniel Zivkovic

Opinionated re:Invent recap with AWS Heroes & Builders
Opinionated re:Invent recap with AWS Heroes & BuildersOpinionated re:Invent recap with AWS Heroes & Builders
Opinionated re:Invent recap with AWS Heroes & Builders
Daniel Zivkovic
 
Intro to Vertex AI, unified MLOps platform for Data Scientists & ML Engineers
Intro to Vertex AI, unified MLOps platform for Data Scientists & ML EngineersIntro to Vertex AI, unified MLOps platform for Data Scientists & ML Engineers
Intro to Vertex AI, unified MLOps platform for Data Scientists & ML Engineers
Daniel Zivkovic
 
This is my Architecture to prevent Cloud Bill Shock
This is my Architecture to prevent Cloud Bill ShockThis is my Architecture to prevent Cloud Bill Shock
This is my Architecture to prevent Cloud Bill Shock
Daniel Zivkovic
 
Azure for AWS & GCP Pros: Which Azure services to use?
Azure for AWS & GCP Pros: Which Azure services to use?Azure for AWS & GCP Pros: Which Azure services to use?
Azure for AWS & GCP Pros: Which Azure services to use?
Daniel Zivkovic
 
Serverless Evolution during 3 years of Serverless Toronto
Serverless Evolution during 3 years of Serverless TorontoServerless Evolution during 3 years of Serverless Toronto
Serverless Evolution during 3 years of Serverless Toronto
Daniel Zivkovic
 

Más de Daniel Zivkovic (20)

All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...
All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...
All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...
 
Canadian Experts Discuss Modern Data Stacks and Cloud Computing for 5 Years o...
Canadian Experts Discuss Modern Data Stacks and Cloud Computing for 5 Years o...Canadian Experts Discuss Modern Data Stacks and Cloud Computing for 5 Years o...
Canadian Experts Discuss Modern Data Stacks and Cloud Computing for 5 Years o...
 
Opinionated re:Invent recap with AWS Heroes & Builders
Opinionated re:Invent recap with AWS Heroes & BuildersOpinionated re:Invent recap with AWS Heroes & Builders
Opinionated re:Invent recap with AWS Heroes & Builders
 
Google Cloud Next '22 Recap: Serverless & Data edition
Google Cloud Next '22 Recap: Serverless & Data editionGoogle Cloud Next '22 Recap: Serverless & Data edition
Google Cloud Next '22 Recap: Serverless & Data edition
 
Conversational Document Processing AI with Rui Costa
Conversational Document Processing AI with Rui CostaConversational Document Processing AI with Rui Costa
Conversational Document Processing AI with Rui Costa
 
How to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
How to build unified Batch & Streaming Pipelines with Apache Beam and DataflowHow to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
How to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
 
Gojko's 5 rules for super responsive Serverless applications
Gojko's 5 rules for super responsive Serverless applicationsGojko's 5 rules for super responsive Serverless applications
Gojko's 5 rules for super responsive Serverless applications
 
Retail Analytics and BI with Looker, BigQuery, GCP & Leigha Jarett
Retail Analytics and BI with Looker, BigQuery, GCP & Leigha JarettRetail Analytics and BI with Looker, BigQuery, GCP & Leigha Jarett
Retail Analytics and BI with Looker, BigQuery, GCP & Leigha Jarett
 
What's new in Serverless at AWS?
What's new in Serverless at AWS?What's new in Serverless at AWS?
What's new in Serverless at AWS?
 
Intro to Vertex AI, unified MLOps platform for Data Scientists & ML Engineers
Intro to Vertex AI, unified MLOps platform for Data Scientists & ML EngineersIntro to Vertex AI, unified MLOps platform for Data Scientists & ML Engineers
Intro to Vertex AI, unified MLOps platform for Data Scientists & ML Engineers
 
Empowering Developers to be Healthcare Heroes
Empowering Developers to be Healthcare HeroesEmpowering Developers to be Healthcare Heroes
Empowering Developers to be Healthcare Heroes
 
Get started with Dialogflow & Contact Center AI on Google Cloud
Get started with Dialogflow & Contact Center AI on Google CloudGet started with Dialogflow & Contact Center AI on Google Cloud
Get started with Dialogflow & Contact Center AI on Google Cloud
 
Building a Data Cloud to enable Analytics & AI-Driven Innovation - Lak Lakshm...
Building a Data Cloud to enable Analytics & AI-Driven Innovation - Lak Lakshm...Building a Data Cloud to enable Analytics & AI-Driven Innovation - Lak Lakshm...
Building a Data Cloud to enable Analytics & AI-Driven Innovation - Lak Lakshm...
 
Smart Cities of Italy: Integrating the Cyber World with the IoT
Smart Cities of Italy: Integrating the Cyber World with the IoTSmart Cities of Italy: Integrating the Cyber World with the IoT
Smart Cities of Italy: Integrating the Cyber World with the IoT
 
Running Business Analytics for a Serverless Insurance Company - Joe Emison & ...
Running Business Analytics for a Serverless Insurance Company - Joe Emison & ...Running Business Analytics for a Serverless Insurance Company - Joe Emison & ...
Running Business Analytics for a Serverless Insurance Company - Joe Emison & ...
 
This is my Architecture to prevent Cloud Bill Shock
This is my Architecture to prevent Cloud Bill ShockThis is my Architecture to prevent Cloud Bill Shock
This is my Architecture to prevent Cloud Bill Shock
 
Lunch & Learn BigQuery & Firebase from other Google Cloud customers
Lunch & Learn BigQuery & Firebase from other Google Cloud customersLunch & Learn BigQuery & Firebase from other Google Cloud customers
Lunch & Learn BigQuery & Firebase from other Google Cloud customers
 
Azure for AWS & GCP Pros: Which Azure services to use?
Azure for AWS & GCP Pros: Which Azure services to use?Azure for AWS & GCP Pros: Which Azure services to use?
Azure for AWS & GCP Pros: Which Azure services to use?
 
Serverless Evolution during 3 years of Serverless Toronto
Serverless Evolution during 3 years of Serverless TorontoServerless Evolution during 3 years of Serverless Toronto
Serverless Evolution during 3 years of Serverless Toronto
 
Simpler, faster, cheaper Enterprise Apps using only Spring Boot on GCP
Simpler, faster, cheaper Enterprise Apps using only Spring Boot on GCPSimpler, faster, cheaper Enterprise Apps using only Spring Boot on GCP
Simpler, faster, cheaper Enterprise Apps using only Spring Boot on GCP
 

Último

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Último (20)

Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 

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