SlideShare a Scribd company logo
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Heitor Lessa, Serverless Specialist SA
lessa@amazon.com
Serverless Best Practices
a.k.a lessons learned from the field
@heitor_lessa
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Agenda
• Design principles for Serverless Applications
• Best practices
• Deployment
• Testing
• Monitoring
• Security
• Performance
• Microservices
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Design principles for Serverless
applications
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
General design principles
Speedy, simple, singular
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Instead of Lambda based “monoliths”….
GET /pets
PUT /pets
DELETE /pets
GET /describe/pet/$id
PUT /describe/pet/$id
ONE LARGE LAMBDA FUNCTIONEVENT DRIVEN
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Lambda based “nano-services”
EVENT DRIVEN Constellation of functions
GET /pets
PUT /pets
DELETE /pets
GET /describe/pet/$id
PUT /describe/pet/$id
Amazon
API Gateway
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
General design principles
Think concurrent requests, not total
requests
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Compute power: Don’t “guesstimate”
alexcasalboni
aws-lambda-power-tuning
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
General design principles
Share nothing
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Leverage container reuse but persistent storage for durable
state
s3 = boto3.resource('s3')
db = db.connect()
def lambda_handler(event, context):
global db
# verify if still connected
# otherwise carry on
if not db:
db = db.connect()
…
db.save(highly_durable_state)
...
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
General design principles
Orchestrate your application with
state machines, not functions
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Don’t orchestrate within your functions…STARTJOB
JOB#XSTARTED
HTTPPOST
HTTPPOST
AREWETHEREYET?
NOPE!
WE’REDONE!
ZzZz
OR
time.sleep(10)
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Step Functions with AWS Batch
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
General design principles
Design for failures and duplicates
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Applying Saga pattern with AWS Step Functions
theburningmonk.com/2017/07/applying-the-saga-pattern-with-aws-lambda-and-step-functions
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Best practices
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Deployment
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
• Single responsibility principle == Single function
• Share resource information across stacks via
Export value or SSM Parameter Store
• Build out multiple environments, such as for
Development, Test, Production and even DR using
the same template, even across accounts
• Shared code == Language specific packages
Shared Event Source == Same template
SAM Template
Source
Control
Dev
Test
Prod
Deployment best practices
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Testing
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Testing strategies
Run Unit tests locally
Run Integration/Acceptance tests with real services
Leverage SAM Local and Lambda runtime AMI
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Monitoring
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Cloudwatch – Metrics and streaming
Alarm on individual and aggregate metrics
(Throttling alarm !== Errors/Duration alarm)
Create Custom Metrics via Metric Filter
(Centralize logs from multiple accounts to Amazon ES)
Drill down application insights with X-Ray
(Too much time spent at logs == Lack of metrics)
Log only what’s necessary
(Use Environment Variables to control logging level)
built-in custom
Amazon Cloudwatch
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
X-Ray – Application Insights
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Application instrumentation (Node.js)
const AWSXRay = require('aws-xray-sdk-core');
# Wraps AWS SDK and trace subsequent AWS Services
const AWS = AWSXRay.captureAWS(require('aws-sdk'));
const dynamoDb = new AWS.DynamoDB.DocumentClient();
const sqs = new AWS.SQS();
# Wraps HTTP calls made
const https = AWSXRay.captureHTTPs(require('https'));
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Security
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Vulnerabilities and security scan
Application Security Best practices still apply
(Input validation/sanitization, code review, etc..)
One IAM Role per function
(permissions are easy to add but hard to remove)
Encrypt secrets with KMS integration
(Leverage EC2 SSM Parameter Store for shared secrets)
Automate security scans/controls into CI/CD
(Dependency CVEs, static/dynamic analysis, etc.)
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
What about cold starts?
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
As seen on TV…
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Cold start: Understand the function lifecycle
Download
your code
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Download
your code
Start new
process
Cold start: Understand the function lifecycle
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Bootstrap
the runtime
Cold start: Understand the function lifecycle
Download
your code
Start new
process
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Bootstrap
the runtime
Start your
code
Cold start: Understand the function lifecycle
Download
your code
Start new
process
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Bootstrap
the runtime
Start your
code
Cold start: Understand the function lifecycle
Full
cold start
Partial
cold start
Warm
start
Download
your code*
Start new
process
AWS optimization Your optimization
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Download
your code*
Start new
process
Create
VPC ENI
Start your
code
Attach
VPC ENI
Full
cold start
Warm
start
Bootstrap
runtime
Partial
cold start
AWS optimization Your optimization
Cold start: Understand the function lifecycle
(VPC)
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Don’t panic – Prod is consistent! VPC numbers
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Look at the distribution not average
TP99: 99% of reqs were
below this data point
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
TP99: 99% of reqs were
below this data point
TP50/Median: 50% either
above or below
Look at the distribution not average
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
What about Microservices?
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Just because you use Lambda, it’s not a micro
service
Ingest()
sanitize()
attach_
metadata()
cache()
This fails all three tenets: it’s not decoupled, has multiple
owners, it’s still a monolith to build
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
We can isolate a few services here
Ingest() sanitize() attach_
metadata()
cache
• Ingestion and sanitization live together
• Metadata should be a separate database/service,
queried by the ingestion service
• Cache and frontend should be a separate service that
uses data from the previous two
• You need to own the interfaces!
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Do you re-use services? APIs are the contract
Ingestion service
Ingestion
API
ingest
&
sanitize()
Metadata service
CRUD
API
read & write
metadata()
Frontend service
Frontend
API
express()
• We can create a new ingestion service that re-uses the
same metadata service
• We can modify the frontend without touching how the data is received and
processed
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Recap
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Key takeaways
Security application best
practices still apply
Decouple orchestration logic
from application logic
Optimize for single purpose;
leverage concurrency model
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Appendix
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Additional Resources - Whitepaper
Serverless Architectures
with AWS Lambda
November 2017
bit.ly/2zVvp0w
Optimizing Enterprise
Economics with
Serverless
Architectures
October 2017
bit.ly/2hQdy44
Serverless Applications
Lens
November 2017
bit.ly/serverless_lens
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Additional Resources - Playlist
re:Invent 2017 – Serverless Breakout Sessions
bit.ly/serverless_playlist17

More Related Content

What's hot

What's hot (20)

Manage, Control, and Optimize Your AWS Costs with Native AWS Products (ENT305...
Manage, Control, and Optimize Your AWS Costs with Native AWS Products (ENT305...Manage, Control, and Optimize Your AWS Costs with Native AWS Products (ENT305...
Manage, Control, and Optimize Your AWS Costs with Native AWS Products (ENT305...
 
Applying the Twelve-Factor App Methodology to Serverless Applications (SRV218...
Applying the Twelve-Factor App Methodology to Serverless Applications (SRV218...Applying the Twelve-Factor App Methodology to Serverless Applications (SRV218...
Applying the Twelve-Factor App Methodology to Serverless Applications (SRV218...
 
Deep dive - AWS Fargate
Deep dive - AWS FargateDeep dive - AWS Fargate
Deep dive - AWS Fargate
 
Breaking Containers: Chaos Engineering for Modern Applications on AWS (CON310...
Breaking Containers: Chaos Engineering for Modern Applications on AWS (CON310...Breaking Containers: Chaos Engineering for Modern Applications on AWS (CON310...
Breaking Containers: Chaos Engineering for Modern Applications on AWS (CON310...
 
Prepare Your Team for Cloud Transformation
Prepare Your Team for Cloud Transformation Prepare Your Team for Cloud Transformation
Prepare Your Team for Cloud Transformation
 
Build a Searchable Media Library & Moderate Content at Scale Using Machine Le...
Build a Searchable Media Library & Moderate Content at Scale Using Machine Le...Build a Searchable Media Library & Moderate Content at Scale Using Machine Le...
Build a Searchable Media Library & Moderate Content at Scale Using Machine Le...
 
Reactive Microservices with AWS Lambda (SRV201-R1) - AWS re:Invent 2018
Reactive Microservices with AWS Lambda (SRV201-R1) - AWS re:Invent 2018Reactive Microservices with AWS Lambda (SRV201-R1) - AWS re:Invent 2018
Reactive Microservices with AWS Lambda (SRV201-R1) - AWS re:Invent 2018
 
Continuous Compliance for Modern Application Pipelines (GPSWS402) - AWS re:In...
Continuous Compliance for Modern Application Pipelines (GPSWS402) - AWS re:In...Continuous Compliance for Modern Application Pipelines (GPSWS402) - AWS re:In...
Continuous Compliance for Modern Application Pipelines (GPSWS402) - AWS re:In...
 
Machine Learning at the IoT Edge (IOT214) - AWS re:Invent 2018
Machine Learning at the IoT Edge (IOT214) - AWS re:Invent 2018Machine Learning at the IoT Edge (IOT214) - AWS re:Invent 2018
Machine Learning at the IoT Edge (IOT214) - AWS re:Invent 2018
 
Day Two Operations of Kubernetes on AWS (GPSTEC309) - AWS re:Invent 2018
Day Two Operations of Kubernetes on AWS (GPSTEC309) - AWS re:Invent 2018Day Two Operations of Kubernetes on AWS (GPSTEC309) - AWS re:Invent 2018
Day Two Operations of Kubernetes on AWS (GPSTEC309) - AWS re:Invent 2018
 
Deep Learning Demystified - A (Mostly) Effortless Introduction: AWS Developer...
Deep Learning Demystified - A (Mostly) Effortless Introduction: AWS Developer...Deep Learning Demystified - A (Mostly) Effortless Introduction: AWS Developer...
Deep Learning Demystified - A (Mostly) Effortless Introduction: AWS Developer...
 
Deploying Your ONNX Deep Learning with Apache MXNet Model Server (AIM413) - A...
Deploying Your ONNX Deep Learning with Apache MXNet Model Server (AIM413) - A...Deploying Your ONNX Deep Learning with Apache MXNet Model Server (AIM413) - A...
Deploying Your ONNX Deep Learning with Apache MXNet Model Server (AIM413) - A...
 
AWS Snowball Edge and AWS Greengrass for Fun and Profit (STG388) - AWS re:Inv...
AWS Snowball Edge and AWS Greengrass for Fun and Profit (STG388) - AWS re:Inv...AWS Snowball Edge and AWS Greengrass for Fun and Profit (STG388) - AWS re:Inv...
AWS Snowball Edge and AWS Greengrass for Fun and Profit (STG388) - AWS re:Inv...
 
Understanding Graph Databases: AWS Developer Workshop at Web Summit
Understanding Graph Databases: AWS Developer Workshop at Web SummitUnderstanding Graph Databases: AWS Developer Workshop at Web Summit
Understanding Graph Databases: AWS Developer Workshop at Web Summit
 
Introduction to AI services for Developers - Builders Day Israel
Introduction to AI services for Developers - Builders Day IsraelIntroduction to AI services for Developers - Builders Day Israel
Introduction to AI services for Developers - Builders Day Israel
 
Breaking Observability Chaos: Best Practices to Monitor AWS Cloud Native Apps...
Breaking Observability Chaos: Best Practices to Monitor AWS Cloud Native Apps...Breaking Observability Chaos: Best Practices to Monitor AWS Cloud Native Apps...
Breaking Observability Chaos: Best Practices to Monitor AWS Cloud Native Apps...
 
Industrialize Machine Learning Using CI/CD Techniques (FSV304-i) - AWS re:Inv...
Industrialize Machine Learning Using CI/CD Techniques (FSV304-i) - AWS re:Inv...Industrialize Machine Learning Using CI/CD Techniques (FSV304-i) - AWS re:Inv...
Industrialize Machine Learning Using CI/CD Techniques (FSV304-i) - AWS re:Inv...
 
Voice-Powered Serverless Analytics (SRV240-R1) - AWS re:Invent 2018
Voice-Powered Serverless Analytics (SRV240-R1) - AWS re:Invent 2018Voice-Powered Serverless Analytics (SRV240-R1) - AWS re:Invent 2018
Voice-Powered Serverless Analytics (SRV240-R1) - AWS re:Invent 2018
 
The Theory and Math Behind Data Privacy and Security Assurance (SEC301) - AWS...
The Theory and Math Behind Data Privacy and Security Assurance (SEC301) - AWS...The Theory and Math Behind Data Privacy and Security Assurance (SEC301) - AWS...
The Theory and Math Behind Data Privacy and Security Assurance (SEC301) - AWS...
 
Monitoring for Operational Outcomes and Application Insights: Best Practices ...
Monitoring for Operational Outcomes and Application Insights: Best Practices ...Monitoring for Operational Outcomes and Application Insights: Best Practices ...
Monitoring for Operational Outcomes and Application Insights: Best Practices ...
 

Similar to Serverless best practices plus design principles 20m version

Similar to Serverless best practices plus design principles 20m version (20)

Microservices for Startups
Microservices for StartupsMicroservices for Startups
Microservices for Startups
 
Cheat your Way into the Cloud
Cheat your Way into the CloudCheat your Way into the Cloud
Cheat your Way into the Cloud
 
AWS Lambda use cases and best practices - Builders Day Israel
AWS Lambda use cases and best practices - Builders Day IsraelAWS Lambda use cases and best practices - Builders Day Israel
AWS Lambda use cases and best practices - Builders Day Israel
 
Build and Test a Serverless Error-Tracking Tool in One Weekend (SRV346-R1) - ...
Build and Test a Serverless Error-Tracking Tool in One Weekend (SRV346-R1) - ...Build and Test a Serverless Error-Tracking Tool in One Weekend (SRV346-R1) - ...
Build and Test a Serverless Error-Tracking Tool in One Weekend (SRV346-R1) - ...
 
Debug your Container and Serverless Applications with AWS X-Ray in 5 Minutes ...
Debug your Container and Serverless Applications with AWS X-Ray in 5 Minutes ...Debug your Container and Serverless Applications with AWS X-Ray in 5 Minutes ...
Debug your Container and Serverless Applications with AWS X-Ray in 5 Minutes ...
 
深入淺出學習雲端開發軟件 AWS Cloud9
深入淺出學習雲端開發軟件 AWS Cloud9深入淺出學習雲端開發軟件 AWS Cloud9
深入淺出學習雲端開發軟件 AWS Cloud9
 
Wildrydes Serverless Workshop Tel Aviv
Wildrydes Serverless Workshop Tel AvivWildrydes Serverless Workshop Tel Aviv
Wildrydes Serverless Workshop Tel Aviv
 
Safeguard the Integrity of Your Code for Fast and Secure Deployments (DEV349-...
Safeguard the Integrity of Your Code for Fast and Secure Deployments (DEV349-...Safeguard the Integrity of Your Code for Fast and Secure Deployments (DEV349-...
Safeguard the Integrity of Your Code for Fast and Secure Deployments (DEV349-...
 
[REPEAT 1] Safeguard the Integrity of Your Code for Fast and Secure Deploymen...
[REPEAT 1] Safeguard the Integrity of Your Code for Fast and Secure Deploymen...[REPEAT 1] Safeguard the Integrity of Your Code for Fast and Secure Deploymen...
[REPEAT 1] Safeguard the Integrity of Your Code for Fast and Secure Deploymen...
 
Building Microservices with the Twelve-Factor App Pattern - SRV346 - Chicago ...
Building Microservices with the Twelve-Factor App Pattern - SRV346 - Chicago ...Building Microservices with the Twelve-Factor App Pattern - SRV346 - Chicago ...
Building Microservices with the Twelve-Factor App Pattern - SRV346 - Chicago ...
 
The Serverless Tidal Wave - SwampUP 2018 Keynote
The Serverless Tidal Wave - SwampUP 2018 KeynoteThe Serverless Tidal Wave - SwampUP 2018 Keynote
The Serverless Tidal Wave - SwampUP 2018 Keynote
 
以 12 要素應用模式在 AWS 上構建微服務
以 12 要素應用模式在 AWS 上構建微服務以 12 要素應用模式在 AWS 上構建微服務
以 12 要素應用模式在 AWS 上構建微服務
 
Instrumenting Kubernetes for Observability Using AWS X-Ray and Amazon CloudWa...
Instrumenting Kubernetes for Observability Using AWS X-Ray and Amazon CloudWa...Instrumenting Kubernetes for Observability Using AWS X-Ray and Amazon CloudWa...
Instrumenting Kubernetes for Observability Using AWS X-Ray and Amazon CloudWa...
 
Developing Serverless Application on AWS
Developing Serverless Application on AWSDeveloping Serverless Application on AWS
Developing Serverless Application on AWS
 
Building Microservices with the 12 Factor App Pattern on AWS - Tony Pujals
Building Microservices with the 12 Factor App Pattern on AWS - Tony PujalsBuilding Microservices with the 12 Factor App Pattern on AWS - Tony Pujals
Building Microservices with the 12 Factor App Pattern on AWS - Tony Pujals
 
CI/CD for Your Machine Learning Pipeline with Amazon SageMaker (DVC303) - AWS...
CI/CD for Your Machine Learning Pipeline with Amazon SageMaker (DVC303) - AWS...CI/CD for Your Machine Learning Pipeline with Amazon SageMaker (DVC303) - AWS...
CI/CD for Your Machine Learning Pipeline with Amazon SageMaker (DVC303) - AWS...
 
Introduction to Serverless on AWS
Introduction to Serverless on AWSIntroduction to Serverless on AWS
Introduction to Serverless on AWS
 
Building Microservices with the 12 Factor App Pattern on AWS.pdf
Building Microservices with the 12 Factor App Pattern on AWS.pdfBuilding Microservices with the 12 Factor App Pattern on AWS.pdf
Building Microservices with the 12 Factor App Pattern on AWS.pdf
 
Serverless Architectural Patterns and Best Practices
Serverless Architectural Patterns and Best PracticesServerless Architectural Patterns and Best Practices
Serverless Architectural Patterns and Best Practices
 
From Code to a Running Container | AWS Floor28
From Code to a Running Container | AWS Floor28From Code to a Running Container | AWS Floor28
From Code to a Running Container | AWS Floor28
 

More from Heitor Lessa

Organising time effectively
Organising time effectivelyOrganising time effectively
Organising time effectively
Heitor Lessa
 

More from Heitor Lessa (9)

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
 
re:Invent OPN306 AWS Lambda Powertools Lessons 10M downloads.pdf
re:Invent OPN306 AWS Lambda Powertools Lessons 10M downloads.pdfre:Invent OPN306 AWS Lambda Powertools Lessons 10M downloads.pdf
re:Invent OPN306 AWS Lambda Powertools Lessons 10M downloads.pdf
 
AWS Lambda Powertools walkthrough.pdf
AWS Lambda Powertools walkthrough.pdfAWS Lambda Powertools walkthrough.pdf
AWS Lambda Powertools walkthrough.pdf
 
AWS Community Day Ireland - Building roads and bridges in the last decade of ...
AWS Community Day Ireland - Building roads and bridges in the last decade of ...AWS Community Day Ireland - Building roads and bridges in the last decade of ...
AWS Community Day Ireland - Building roads and bridges in the last decade of ...
 
AWS Community Day Ireland - Refactoring a serverless app
AWS Community Day Ireland - Refactoring a serverless appAWS Community Day Ireland - Refactoring a serverless app
AWS Community Day Ireland - Refactoring a serverless app
 
AWS Lambda Powertools
AWS Lambda PowertoolsAWS Lambda Powertools
AWS Lambda Powertools
 
Serverless days Stockholm - How to build a full-stack airline ticketing web app
Serverless days Stockholm - How to build a full-stack airline ticketing web appServerless days Stockholm - How to build a full-stack airline ticketing web app
Serverless days Stockholm - How to build a full-stack airline ticketing web app
 
ArmadaJS - how to build a full-stack airline ticketing web app
ArmadaJS - how to build a full-stack airline ticketing web appArmadaJS - how to build a full-stack airline ticketing web app
ArmadaJS - how to build a full-stack airline ticketing web app
 
Organising time effectively
Organising time effectivelyOrganising time effectively
Organising time effectively
 

Recently uploaded

Recently uploaded (20)

top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
GraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisGraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysis
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdfA Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting software
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 

Serverless best practices plus design principles 20m version

  • 1. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Heitor Lessa, Serverless Specialist SA lessa@amazon.com Serverless Best Practices a.k.a lessons learned from the field @heitor_lessa
  • 2. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 3. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Agenda • Design principles for Serverless Applications • Best practices • Deployment • Testing • Monitoring • Security • Performance • Microservices
  • 4. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Design principles for Serverless applications
  • 5. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. General design principles Speedy, simple, singular
  • 6. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Instead of Lambda based “monoliths”…. GET /pets PUT /pets DELETE /pets GET /describe/pet/$id PUT /describe/pet/$id ONE LARGE LAMBDA FUNCTIONEVENT DRIVEN
  • 7. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Lambda based “nano-services” EVENT DRIVEN Constellation of functions GET /pets PUT /pets DELETE /pets GET /describe/pet/$id PUT /describe/pet/$id Amazon API Gateway
  • 8. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. General design principles Think concurrent requests, not total requests
  • 9. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Compute power: Don’t “guesstimate” alexcasalboni aws-lambda-power-tuning
  • 10. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. General design principles Share nothing
  • 11. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Leverage container reuse but persistent storage for durable state s3 = boto3.resource('s3') db = db.connect() def lambda_handler(event, context): global db # verify if still connected # otherwise carry on if not db: db = db.connect() … db.save(highly_durable_state) ...
  • 12. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. General design principles Orchestrate your application with state machines, not functions
  • 13. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Don’t orchestrate within your functions…STARTJOB JOB#XSTARTED HTTPPOST HTTPPOST AREWETHEREYET? NOPE! WE’REDONE! ZzZz OR time.sleep(10)
  • 14. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Step Functions with AWS Batch
  • 15. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. General design principles Design for failures and duplicates
  • 16. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Applying Saga pattern with AWS Step Functions theburningmonk.com/2017/07/applying-the-saga-pattern-with-aws-lambda-and-step-functions
  • 17. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Best practices
  • 18. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Deployment
  • 19. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. • Single responsibility principle == Single function • Share resource information across stacks via Export value or SSM Parameter Store • Build out multiple environments, such as for Development, Test, Production and even DR using the same template, even across accounts • Shared code == Language specific packages Shared Event Source == Same template SAM Template Source Control Dev Test Prod Deployment best practices
  • 20. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Testing
  • 21. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Testing strategies Run Unit tests locally Run Integration/Acceptance tests with real services Leverage SAM Local and Lambda runtime AMI
  • 22. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Monitoring
  • 23. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Cloudwatch – Metrics and streaming Alarm on individual and aggregate metrics (Throttling alarm !== Errors/Duration alarm) Create Custom Metrics via Metric Filter (Centralize logs from multiple accounts to Amazon ES) Drill down application insights with X-Ray (Too much time spent at logs == Lack of metrics) Log only what’s necessary (Use Environment Variables to control logging level) built-in custom Amazon Cloudwatch
  • 24. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. X-Ray – Application Insights
  • 25. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Application instrumentation (Node.js) const AWSXRay = require('aws-xray-sdk-core'); # Wraps AWS SDK and trace subsequent AWS Services const AWS = AWSXRay.captureAWS(require('aws-sdk')); const dynamoDb = new AWS.DynamoDB.DocumentClient(); const sqs = new AWS.SQS(); # Wraps HTTP calls made const https = AWSXRay.captureHTTPs(require('https'));
  • 26. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Security
  • 27. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Vulnerabilities and security scan Application Security Best practices still apply (Input validation/sanitization, code review, etc..) One IAM Role per function (permissions are easy to add but hard to remove) Encrypt secrets with KMS integration (Leverage EC2 SSM Parameter Store for shared secrets) Automate security scans/controls into CI/CD (Dependency CVEs, static/dynamic analysis, etc.)
  • 28. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. What about cold starts?
  • 29. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. As seen on TV…
  • 30. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Cold start: Understand the function lifecycle Download your code
  • 31. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Download your code Start new process Cold start: Understand the function lifecycle
  • 32. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Bootstrap the runtime Cold start: Understand the function lifecycle Download your code Start new process
  • 33. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Bootstrap the runtime Start your code Cold start: Understand the function lifecycle Download your code Start new process
  • 34. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Bootstrap the runtime Start your code Cold start: Understand the function lifecycle Full cold start Partial cold start Warm start Download your code* Start new process AWS optimization Your optimization
  • 35. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Download your code* Start new process Create VPC ENI Start your code Attach VPC ENI Full cold start Warm start Bootstrap runtime Partial cold start AWS optimization Your optimization Cold start: Understand the function lifecycle (VPC)
  • 36. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Don’t panic – Prod is consistent! VPC numbers
  • 37. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Look at the distribution not average TP99: 99% of reqs were below this data point
  • 38. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. TP99: 99% of reqs were below this data point TP50/Median: 50% either above or below Look at the distribution not average
  • 39. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. What about Microservices?
  • 40. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Just because you use Lambda, it’s not a micro service Ingest() sanitize() attach_ metadata() cache() This fails all three tenets: it’s not decoupled, has multiple owners, it’s still a monolith to build
  • 41. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. We can isolate a few services here Ingest() sanitize() attach_ metadata() cache • Ingestion and sanitization live together • Metadata should be a separate database/service, queried by the ingestion service • Cache and frontend should be a separate service that uses data from the previous two • You need to own the interfaces!
  • 42. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Do you re-use services? APIs are the contract Ingestion service Ingestion API ingest & sanitize() Metadata service CRUD API read & write metadata() Frontend service Frontend API express() • We can create a new ingestion service that re-uses the same metadata service • We can modify the frontend without touching how the data is received and processed
  • 43. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Recap
  • 44. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Key takeaways Security application best practices still apply Decouple orchestration logic from application logic Optimize for single purpose; leverage concurrency model
  • 45. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Appendix
  • 46. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Additional Resources - Whitepaper Serverless Architectures with AWS Lambda November 2017 bit.ly/2zVvp0w Optimizing Enterprise Economics with Serverless Architectures October 2017 bit.ly/2hQdy44 Serverless Applications Lens November 2017 bit.ly/serverless_lens
  • 47. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Additional Resources - Playlist re:Invent 2017 – Serverless Breakout Sessions bit.ly/serverless_playlist17