SlideShare uma empresa Scribd logo
1 de 29
Serverless
patterns & best-
practices in AWS
Dima Pasko, SA
This presentation has been prepared by EPAM Systems, Inc. solely for use by EPAM at its EPAM Zed
Conference. This presentation or the information contained herein may not be reproduced or used
for any other purpose. This presentation includes highly confidential and proprietary information and
is delivered on the express condition that such information will not be disclosed to anyone except
persons in the recipient organization who have a need to know solely for the purpose described
above. No copies of this presentation will be made, and no other distribution will be made, without
the consent of EPAM. Any distribution of this presentation to any other person, in whole or in part,
or the reproduction of this presentation, or the divulgence of any of its contents is unauthorized.
CONFIDENTIAL INFORMATION
Dima Pasko
Solution Architect II
EPAM Systems
What Serverless Is
Serverless computing is a cloud computing execution model in which the cloud provider
allocates machine resources on demand, taking care of the servers on behalf of their customers…
© Wikipedia https://en.wikipedia.org/wiki/Serverless_computing
The Business Case
For Serverless
Focus on business value, not infrastructure
1. F A S T E R T I M E T O M A R K E T
2.
3.
R E D U C E D C O S T S
I M P R O V E D R E L I A B I L I T Y
6
4. I N C R E A S E D R AT E O F I N N O VAT I O N
Faster time to market
By eliminating operational overhead, your teams can release quickly, get
feedback, and iterate to get to market faster.
Reduced costs
With a pay-for-value billing model, you never pay for over-provisioning and
your resource utilization is optimized on your behalf.
Improved reliability
With technologies that automatically scale from zero to peak demands, you
can adapt to customer needs faster than ever.
Increased rate of innovation
Serverless applications have built-in service integrations, so you can focus on
building your application instead of configuring it.
AWS Serverless Design
Patterns & Solutions
Review
AWS Lambda/Serverless patterns overview
AWS designed many solutions, and you should just find building
blocks for your cases
• Web application
• Mobile application for social distancing
• Mobile back-end
• Real-time stream processing
• IoT back-end
• AWS Connected mobility architecture
• Real-time file processing
• MapReduce
• Image recognition & processing
• Image moderator chatbot
12
https://aws.amazon.com/lambda/resources/reference-architectures/
AWS Serverless Application Lens
13
AWS Well-Architected Tool
AWS Well-Architected Framework
Serverless Lens
FTR Lens
SaaS Lens
Operational excellence
Security
Reliability
Performance efficiency
Cost Optimization
Workload Review Report
AWS Serverless Application Lens Report Example (General)
14
AWS Serverless Application Lens Report Example (Details)
15
Serverless Myths &
Design Anti-Patterns
Myths
Myth #1: Serverless means “no server and hardware”
• You need to setup required RAM size
Myth #2: Serverless == Lambda (AWS Lambda, Azure Functions etc.)
• Amazon enumerates as serverless such services as S3, SQS, SNS, API Gateway, DynamoDB
Myth #3: Serverless is cheap, definitely cheaper than “serverfull” solution
• Not always, you always should calculate costs ahead to see if it’s good fit
Going Stateful Anti-Pattern
Antipattern #1: Going stateful (in-memory state)
Problem
• Though lambda instance can be preserved for the next requests (such called
“hot start”), it is not guaranteed
• After lambda run, lambda instance can be terminated anytime
Solution
• You need a state, store it in external services
18
Do Not Pay Attention To Service Specifics
Antipattern #2: Do not pay attention to service specifics
Problem
• “I just write my code and deploy it to AWS Lambda – and everything works” – right, but only if
you agree with terms of service. AWS Lambda for example, have number of limitations (quotas):
• Request size <= 6Mb (so you cannot use it for file upload, use S3 for that)
• Max execution time is 15 minutes (lambda is terminated by timeout then)
Solution
• Regularly revisit quotas, know your data, check if they fit
• Remember there are hard and soft limits, soft limits can be increased on request
19
My Favorite Stack Is Great At Lambdas
Antipattern #3: Use your favorite tech stack without paying attention at cost
Problem
• Startup can be much slower in comparison to using plain old java or another language
• You are charged on a second basis.
Reducing overall duration from 10 seconds to 5 seconds will cut your costs twice
• Decreasing memory size (because code in Java was rewritten in Go) by two times will cut your costs
twice
Solution
• As lambda should be small, you can write it in Go/Python/JavaScript even if you are not a Pro in this
language
• So the pattern is: consider if the cost benefit worth learning
20
Multithreading Is Great In Lambdas
Antipattern #4: Using old-fashioned way for orchestration
Problem
“I will save a record in DynamoDB from lambda
and then Thread.sleep for another service to update it’s status”
• Each second if lambda does not do anything, you still pay money
• Avoid explicit and try to avoid implicit waits
• Implicit wait – blocking lambda instance awaiting for response from synchronous calls (RESTs)
• Explicit wait – Thread.sleep, polling messages from queues in while loops, checking state in while loops
etc.
Solution
• Orchestration using AWS Step Functions
• Choreography using message brokers (SQS, EventBridge, Kinesis, DynamoDB Streams)
21
Serverless Best Practices
Serverless Application Model
• Build serverless applications in simple and clean syntax
• Features:
• Built on AWS CloudFormation
• Built-In Best Practices
• Single Deployment Configuration
• Local Testing and Debugging
(+ https://localstack.cloud/)
• Serverless Application Model - https://aws.amazon.com/serverless/sam/
AWS CDK
• Define cloud infrastructure using familiar programming languages
• Supported programming languages:
• TypeScript
• Java Script
• Python
• Java
• C# (.NET)
• AWS Solutions Constructs -
https://aws.amazon.com/solutions/constructs/patterns/
• ConstructHub - https://constructs.dev/
• CDK Patterns - https://cdkpatterns.com/
Nested Stacks
• Nested stacks are stacks created as part of other stacks.
• Nested stacks can themselves contain other nested stacks, resulting in a
hierarchy of stacks, as in the diagram below. The root stack is the top-
level stack to which all the nested stacks ultimately belong. In addition,
each nested stack has an immediate parent stack. For the first level of
nested stacks, the root stack is also the parent stack. in the diagram
below, for example:
• Stack A is the root stack for all the other, nested, stacks in the hierarchy.
• For stack B, stack A is both the parent stack, and the root stack.
• For stack D, stack C is the parent stack; while for stack C, stack B is the
parent stack.
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-
cfn-nested-stacks.html
Know Your Limits
• Lambda’s executions
• Concurrent executions - 1,000
• Step Functions
• Maximum number of registered state machines - 10,000
• Maximum open executions per account - 1,000,000 executions
per AWS account.
• ENIs for Lambdas are not endless
• Elastic network interfaces per virtual private cloud (VPC) - 250
• Limit on S3 buckets for Lambdas
• Buckets - 100 per account
AWS Lambda Power Tuning
AWS Lambda Power Tuning is a state machine powered by AWS Step Functions that helps you optimize your Lambda functions for cost
and/or performance in a data-driven way.
https://github.com/alexcasalboni/aws-lambda-power-tuning
DB Connections Management
Serverless works best with services rather than connections.
Connection management:
• Application connection pooling
• RDS Proxy
• Amazon Aurora Serverless v2
• Data API
• Dynamo DB
• https://aws.amazon.com/blogs/database/best-practices-for-working-
with-amazon-aurora-serverless/
Thank you!
For more information, contact
Dima Pasko
Solution Architect II
Dmytro_Pasko@epam.com
https://www.linkedin.com/in/dimapasko

Mais conteúdo relacionado

Mais procurados

AWS Summit Benelux 2013 - Media and Online Advertising on AWS
AWS Summit Benelux 2013 - Media and Online Advertising on AWSAWS Summit Benelux 2013 - Media and Online Advertising on AWS
AWS Summit Benelux 2013 - Media and Online Advertising on AWS
Amazon Web Services
 

Mais procurados (20)

AWS Innovation at Scale
AWS Innovation at ScaleAWS Innovation at Scale
AWS Innovation at Scale
 
Sloppy Little Serverless Stories
Sloppy Little Serverless StoriesSloppy Little Serverless Stories
Sloppy Little Serverless Stories
 
GPU Renderfarm with Integrated Asset Management & Production System (AMPS)
GPU Renderfarm with Integrated Asset Management & Production System (AMPS)GPU Renderfarm with Integrated Asset Management & Production System (AMPS)
GPU Renderfarm with Integrated Asset Management & Production System (AMPS)
 
AWS re:Invent 2016: ElastiCache Deep Dive: Best Practices and Usage Patterns ...
AWS re:Invent 2016: ElastiCache Deep Dive: Best Practices and Usage Patterns ...AWS re:Invent 2016: ElastiCache Deep Dive: Best Practices and Usage Patterns ...
AWS re:Invent 2016: ElastiCache Deep Dive: Best Practices and Usage Patterns ...
 
AWS re:Invent 2016: Best Practices for Data Warehousing with Amazon Redshift ...
AWS re:Invent 2016: Best Practices for Data Warehousing with Amazon Redshift ...AWS re:Invent 2016: Best Practices for Data Warehousing with Amazon Redshift ...
AWS re:Invent 2016: Best Practices for Data Warehousing with Amazon Redshift ...
 
Pragmatic Approach to Workload Migrations - London Summit Enteprise Track RePlay
Pragmatic Approach to Workload Migrations - London Summit Enteprise Track RePlayPragmatic Approach to Workload Migrations - London Summit Enteprise Track RePlay
Pragmatic Approach to Workload Migrations - London Summit Enteprise Track RePlay
 
AWS re:Invent 2016: Optimizing workloads in SAP HANA with Amazon EC2 X1 Insta...
AWS re:Invent 2016: Optimizing workloads in SAP HANA with Amazon EC2 X1 Insta...AWS re:Invent 2016: Optimizing workloads in SAP HANA with Amazon EC2 X1 Insta...
AWS re:Invent 2016: Optimizing workloads in SAP HANA with Amazon EC2 X1 Insta...
 
Serverless
ServerlessServerless
Serverless
 
AWS re:Invent 2016: Design, Deploy, and Optimize Microsoft SharePoint on AWS ...
AWS re:Invent 2016: Design, Deploy, and Optimize Microsoft SharePoint on AWS ...AWS re:Invent 2016: Design, Deploy, and Optimize Microsoft SharePoint on AWS ...
AWS re:Invent 2016: Design, Deploy, and Optimize Microsoft SharePoint on AWS ...
 
AWS re:Invent 2016: Building HPC Clusters as Code in the (Almost) Infinite Cl...
AWS re:Invent 2016: Building HPC Clusters as Code in the (Almost) Infinite Cl...AWS re:Invent 2016: Building HPC Clusters as Code in the (Almost) Infinite Cl...
AWS re:Invent 2016: Building HPC Clusters as Code in the (Almost) Infinite Cl...
 
AWS Summit Benelux 2013 - Media and Online Advertising on AWS
AWS Summit Benelux 2013 - Media and Online Advertising on AWSAWS Summit Benelux 2013 - Media and Online Advertising on AWS
AWS Summit Benelux 2013 - Media and Online Advertising on AWS
 
Why Scale Matters and How the Cloud Really is Different
Why Scale Matters and How the Cloud Really is Different Why Scale Matters and How the Cloud Really is Different
Why Scale Matters and How the Cloud Really is Different
 
AWS re:Invent 2016: High Performance Computing on AWS (CMP207)
AWS re:Invent 2016: High Performance Computing on AWS (CMP207)AWS re:Invent 2016: High Performance Computing on AWS (CMP207)
AWS re:Invent 2016: High Performance Computing on AWS (CMP207)
 
Cost Optimization at Scale
Cost Optimization at ScaleCost Optimization at Scale
Cost Optimization at Scale
 
Building Serverless Web Applications
Building Serverless Web Applications Building Serverless Web Applications
Building Serverless Web Applications
 
Top 5 Ways to Optimize for Cost Efficiency with the Cloud
Top 5 Ways to Optimize for Cost Efficiency with the CloudTop 5 Ways to Optimize for Cost Efficiency with the Cloud
Top 5 Ways to Optimize for Cost Efficiency with the Cloud
 
Container Management with Amazon ECS
Container Management with Amazon ECSContainer Management with Amazon ECS
Container Management with Amazon ECS
 
Migration Recipes for Success - AWS Summit Cape Town 2017
Migration Recipes for Success - AWS Summit Cape Town 2017 Migration Recipes for Success - AWS Summit Cape Town 2017
Migration Recipes for Success - AWS Summit Cape Town 2017
 
Cloud Migration, Application Modernization, and Security
Cloud Migration, Application Modernization, and Security Cloud Migration, Application Modernization, and Security
Cloud Migration, Application Modernization, and Security
 
Aws Summit Berlin 2013 - Understanding database options on AWS
Aws Summit Berlin 2013 - Understanding database options on AWSAws Summit Berlin 2013 - Understanding database options on AWS
Aws Summit Berlin 2013 - Understanding database options on AWS
 

Semelhante a AWS Serverless patterns & best-practices in AWS

Building Serverless Web Applications - DevDay Austin 2017
Building Serverless Web Applications - DevDay Austin 2017Building Serverless Web Applications - DevDay Austin 2017
Building Serverless Web Applications - DevDay Austin 2017
Amazon Web Services
 

Semelhante a AWS Serverless patterns & best-practices in AWS (20)

Serverless at Lifestage
Serverless at LifestageServerless at Lifestage
Serverless at Lifestage
 
Serverlessusecase workshop feb3_v2
Serverlessusecase workshop feb3_v2Serverlessusecase workshop feb3_v2
Serverlessusecase workshop feb3_v2
 
Serverless design considerations for Cloud Native workloads
Serverless design considerations for Cloud Native workloadsServerless design considerations for Cloud Native workloads
Serverless design considerations for Cloud Native workloads
 
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
 
Building Serverless Web Applications - DevDay Austin 2017
Building Serverless Web Applications - DevDay Austin 2017Building Serverless Web Applications - DevDay Austin 2017
Building Serverless Web Applications - DevDay Austin 2017
 
Getting Started with AWS Lambda & Serverless Cloud
Getting Started with AWS Lambda & Serverless CloudGetting Started with AWS Lambda & Serverless Cloud
Getting Started with AWS Lambda & Serverless Cloud
 
AWS Lambda and Serverless Cloud
AWS Lambda and Serverless CloudAWS Lambda and Serverless Cloud
AWS Lambda and Serverless Cloud
 
Aws re invent 2018 recap
Aws re invent 2018 recapAws re invent 2018 recap
Aws re invent 2018 recap
 
Workshop : Wild Rydes Takes Off - The Dawn of a New Unicorn
Workshop : Wild Rydes Takes Off - The Dawn of a New UnicornWorkshop : Wild Rydes Takes Off - The Dawn of a New Unicorn
Workshop : Wild Rydes Takes Off - The Dawn of a New Unicorn
 
Wild Rides Takes off - The Dawn of a New Unicorn
Wild Rides Takes off - The Dawn of a New UnicornWild Rides Takes off - The Dawn of a New Unicorn
Wild Rides Takes off - The Dawn of a New Unicorn
 
Get the EDGE to scale: Using Cloudfront along with edge compute to scale your...
Get the EDGE to scale: Using Cloudfront along with edge compute to scale your...Get the EDGE to scale: Using Cloudfront along with edge compute to scale your...
Get the EDGE to scale: Using Cloudfront along with edge compute to scale your...
 
From AWS to Series A in 5 Easy Pieces
From AWS to Series A in 5 Easy PiecesFrom AWS to Series A in 5 Easy Pieces
From AWS to Series A in 5 Easy Pieces
 
Building Serverless Web Applications - DevDay Los Angeles 2017
Building Serverless Web Applications - DevDay Los Angeles 2017Building Serverless Web Applications - DevDay Los Angeles 2017
Building Serverless Web Applications - DevDay Los Angeles 2017
 
NEW LAUNCH! Bringing AWS Lambda to the Edge
NEW LAUNCH! Bringing AWS Lambda to the EdgeNEW LAUNCH! Bringing AWS Lambda to the Edge
NEW LAUNCH! Bringing AWS Lambda to the Edge
 
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
 
Serverless Architecture Patterns
Serverless Architecture PatternsServerless Architecture Patterns
Serverless Architecture Patterns
 
serverless_architecture_patterns_london_loft.pdf
serverless_architecture_patterns_london_loft.pdfserverless_architecture_patterns_london_loft.pdf
serverless_architecture_patterns_london_loft.pdf
 
AWS re:Invent 2016: The State of Serverless Computing (SVR311)
AWS re:Invent 2016: The State of Serverless Computing (SVR311)AWS re:Invent 2016: The State of Serverless Computing (SVR311)
AWS re:Invent 2016: The State of Serverless Computing (SVR311)
 
Building serverless backends - Tech talk 5 May 2017
Building serverless backends - Tech talk 5 May 2017Building serverless backends - Tech talk 5 May 2017
Building serverless backends - Tech talk 5 May 2017
 
SMC301 The State of Serverless Computing
SMC301 The State of Serverless ComputingSMC301 The State of Serverless Computing
SMC301 The State of Serverless Computing
 

Último

Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac Folorunso
Kayode Fayemi
 
If this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New NigeriaIf this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New Nigeria
Kayode Fayemi
 
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxChiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
raffaeleoman
 
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
Sheetaleventcompany
 
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
amilabibi1
 

Último (20)

Presentation on Engagement in Book Clubs
Presentation on Engagement in Book ClubsPresentation on Engagement in Book Clubs
Presentation on Engagement in Book Clubs
 
Sector 62, Noida Call girls :8448380779 Noida Escorts | 100% verified
Sector 62, Noida Call girls :8448380779 Noida Escorts | 100% verifiedSector 62, Noida Call girls :8448380779 Noida Escorts | 100% verified
Sector 62, Noida Call girls :8448380779 Noida Escorts | 100% verified
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac Folorunso
 
Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510
 
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
 
If this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New NigeriaIf this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New Nigeria
 
Dreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video TreatmentDreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video Treatment
 
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdfAWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
 
Air breathing and respiratory adaptations in diver animals
Air breathing and respiratory adaptations in diver animalsAir breathing and respiratory adaptations in diver animals
Air breathing and respiratory adaptations in diver animals
 
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
 
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdfThe workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
 
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxChiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
 
Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...
Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...
Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...
 
lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.
 
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
 
Causes of poverty in France presentation.pptx
Causes of poverty in France presentation.pptxCauses of poverty in France presentation.pptx
Causes of poverty in France presentation.pptx
 
Report Writing Webinar Training
Report Writing Webinar TrainingReport Writing Webinar Training
Report Writing Webinar Training
 
SaaStr Workshop Wednesday w/ Lucas Price, Yardstick
SaaStr Workshop Wednesday w/ Lucas Price, YardstickSaaStr Workshop Wednesday w/ Lucas Price, Yardstick
SaaStr Workshop Wednesday w/ Lucas Price, Yardstick
 
ICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdfICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdf
 
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
 

AWS Serverless patterns & best-practices in AWS

  • 2. This presentation has been prepared by EPAM Systems, Inc. solely for use by EPAM at its EPAM Zed Conference. This presentation or the information contained herein may not be reproduced or used for any other purpose. This presentation includes highly confidential and proprietary information and is delivered on the express condition that such information will not be disclosed to anyone except persons in the recipient organization who have a need to know solely for the purpose described above. No copies of this presentation will be made, and no other distribution will be made, without the consent of EPAM. Any distribution of this presentation to any other person, in whole or in part, or the reproduction of this presentation, or the divulgence of any of its contents is unauthorized. CONFIDENTIAL INFORMATION
  • 4. What Serverless Is Serverless computing is a cloud computing execution model in which the cloud provider allocates machine resources on demand, taking care of the servers on behalf of their customers… © Wikipedia https://en.wikipedia.org/wiki/Serverless_computing
  • 6. Focus on business value, not infrastructure 1. F A S T E R T I M E T O M A R K E T 2. 3. R E D U C E D C O S T S I M P R O V E D R E L I A B I L I T Y 6 4. I N C R E A S E D R AT E O F I N N O VAT I O N
  • 7. Faster time to market By eliminating operational overhead, your teams can release quickly, get feedback, and iterate to get to market faster.
  • 8. Reduced costs With a pay-for-value billing model, you never pay for over-provisioning and your resource utilization is optimized on your behalf.
  • 9. Improved reliability With technologies that automatically scale from zero to peak demands, you can adapt to customer needs faster than ever.
  • 10. Increased rate of innovation Serverless applications have built-in service integrations, so you can focus on building your application instead of configuring it.
  • 11. AWS Serverless Design Patterns & Solutions Review
  • 12. AWS Lambda/Serverless patterns overview AWS designed many solutions, and you should just find building blocks for your cases • Web application • Mobile application for social distancing • Mobile back-end • Real-time stream processing • IoT back-end • AWS Connected mobility architecture • Real-time file processing • MapReduce • Image recognition & processing • Image moderator chatbot 12 https://aws.amazon.com/lambda/resources/reference-architectures/
  • 13. AWS Serverless Application Lens 13 AWS Well-Architected Tool AWS Well-Architected Framework Serverless Lens FTR Lens SaaS Lens Operational excellence Security Reliability Performance efficiency Cost Optimization Workload Review Report
  • 14. AWS Serverless Application Lens Report Example (General) 14
  • 15. AWS Serverless Application Lens Report Example (Details) 15
  • 16. Serverless Myths & Design Anti-Patterns
  • 17. Myths Myth #1: Serverless means “no server and hardware” • You need to setup required RAM size Myth #2: Serverless == Lambda (AWS Lambda, Azure Functions etc.) • Amazon enumerates as serverless such services as S3, SQS, SNS, API Gateway, DynamoDB Myth #3: Serverless is cheap, definitely cheaper than “serverfull” solution • Not always, you always should calculate costs ahead to see if it’s good fit
  • 18. Going Stateful Anti-Pattern Antipattern #1: Going stateful (in-memory state) Problem • Though lambda instance can be preserved for the next requests (such called “hot start”), it is not guaranteed • After lambda run, lambda instance can be terminated anytime Solution • You need a state, store it in external services 18
  • 19. Do Not Pay Attention To Service Specifics Antipattern #2: Do not pay attention to service specifics Problem • “I just write my code and deploy it to AWS Lambda – and everything works” – right, but only if you agree with terms of service. AWS Lambda for example, have number of limitations (quotas): • Request size <= 6Mb (so you cannot use it for file upload, use S3 for that) • Max execution time is 15 minutes (lambda is terminated by timeout then) Solution • Regularly revisit quotas, know your data, check if they fit • Remember there are hard and soft limits, soft limits can be increased on request 19
  • 20. My Favorite Stack Is Great At Lambdas Antipattern #3: Use your favorite tech stack without paying attention at cost Problem • Startup can be much slower in comparison to using plain old java or another language • You are charged on a second basis. Reducing overall duration from 10 seconds to 5 seconds will cut your costs twice • Decreasing memory size (because code in Java was rewritten in Go) by two times will cut your costs twice Solution • As lambda should be small, you can write it in Go/Python/JavaScript even if you are not a Pro in this language • So the pattern is: consider if the cost benefit worth learning 20
  • 21. Multithreading Is Great In Lambdas Antipattern #4: Using old-fashioned way for orchestration Problem “I will save a record in DynamoDB from lambda and then Thread.sleep for another service to update it’s status” • Each second if lambda does not do anything, you still pay money • Avoid explicit and try to avoid implicit waits • Implicit wait – blocking lambda instance awaiting for response from synchronous calls (RESTs) • Explicit wait – Thread.sleep, polling messages from queues in while loops, checking state in while loops etc. Solution • Orchestration using AWS Step Functions • Choreography using message brokers (SQS, EventBridge, Kinesis, DynamoDB Streams) 21
  • 23. Serverless Application Model • Build serverless applications in simple and clean syntax • Features: • Built on AWS CloudFormation • Built-In Best Practices • Single Deployment Configuration • Local Testing and Debugging (+ https://localstack.cloud/) • Serverless Application Model - https://aws.amazon.com/serverless/sam/
  • 24. AWS CDK • Define cloud infrastructure using familiar programming languages • Supported programming languages: • TypeScript • Java Script • Python • Java • C# (.NET) • AWS Solutions Constructs - https://aws.amazon.com/solutions/constructs/patterns/ • ConstructHub - https://constructs.dev/ • CDK Patterns - https://cdkpatterns.com/
  • 25. Nested Stacks • Nested stacks are stacks created as part of other stacks. • Nested stacks can themselves contain other nested stacks, resulting in a hierarchy of stacks, as in the diagram below. The root stack is the top- level stack to which all the nested stacks ultimately belong. In addition, each nested stack has an immediate parent stack. For the first level of nested stacks, the root stack is also the parent stack. in the diagram below, for example: • Stack A is the root stack for all the other, nested, stacks in the hierarchy. • For stack B, stack A is both the parent stack, and the root stack. • For stack D, stack C is the parent stack; while for stack C, stack B is the parent stack. https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using- cfn-nested-stacks.html
  • 26. Know Your Limits • Lambda’s executions • Concurrent executions - 1,000 • Step Functions • Maximum number of registered state machines - 10,000 • Maximum open executions per account - 1,000,000 executions per AWS account. • ENIs for Lambdas are not endless • Elastic network interfaces per virtual private cloud (VPC) - 250 • Limit on S3 buckets for Lambdas • Buckets - 100 per account
  • 27. AWS Lambda Power Tuning AWS Lambda Power Tuning is a state machine powered by AWS Step Functions that helps you optimize your Lambda functions for cost and/or performance in a data-driven way. https://github.com/alexcasalboni/aws-lambda-power-tuning
  • 28. DB Connections Management Serverless works best with services rather than connections. Connection management: • Application connection pooling • RDS Proxy • Amazon Aurora Serverless v2 • Data API • Dynamo DB • https://aws.amazon.com/blogs/database/best-practices-for-working- with-amazon-aurora-serverless/
  • 29. Thank you! For more information, contact Dima Pasko Solution Architect II Dmytro_Pasko@epam.com https://www.linkedin.com/in/dimapasko

Notas do Editor

  1. Hello ZED Conference 2021 Let’s talk about …
  2. Based on real life experience in Insurance domain
  3. Kharkiv, Ukraine Solution Architect Passionate and successful Architect with over 17 years of experience including 6 years of experience in Software Architecture Experience in Digital Transformation projects with Microservices & Serverless Multi-cloud experience: AWS, Azure
  4. Next evolution of cloud computing. Serverless <> not only lambda, it is serverless DBs Engines, Container services, BPMN engines. Servers not have gone you do not manage them only.
  5. Faster time to market (Business logic –> API) – >Messaging & Orchestration -> Storage & Databases -> Compute -> Physical Infrastructure AWS Lambda automatically runs your code without requiring you to provision or manage infrastructure. Just write the code and upload it to Lambda either as a ZIP file or container image. Focus on most important part of your application Technology abstraction allows us to focus on building just the pieces of code and configuration that are providing truly unique value for the client. Productive for the day one
  6. Cost optimized with millisecond metering With AWS Lambda, you only pay for the compute time you consume, so you’re never paying for over-provisioned infrastructure. You are charged for every millisecond your code executes and the number of times your code is triggered. At its most basic, the cost case for serverless boils down to utilization. You’ve probably seen the numbers — traditional, on-premise datacenter servers tend to be only 15 to 30% utilized. (We’ve even heard that most large EC2 users struggle to reach this utilization rate as well!) Put the other way, that means 70 to 85% of your server costs are dead weight. Waste. Аналогия – абонемент в спортзале No hidden costs: Security Platform outdated (personal story) test environment for 18 teams ~ $400
  7. Scale from zero to infinity and back Consistent performance at any scale(smooths) With AWS Lambda, you can optimize your code execution time by choosing the right memory size for your function. You can also keep your functions initialized and hyper-ready to respond within double digit milliseconds by enabling Provisioned Concurrency.
  8. Easy to start new project, very cheap, modularity, elasticity Experiments, new environment, iteration cycle A lot of integrations. Event based. Out of the box. Architecture improvement: breaking the monolith into functions that could be independently deployed, meant that they were better able to split the team up to work on more things in parallel, and to deploy each feature separately Next evolution of cloud computing. Continuously improving: ARM + Graviton
  9. Don’t invent a wheel and review AWS resources Try to search and adopt existing to your case Also this is a good reason to learn how to draw diagrams for AWS
  10. AWS Well-Architected Framework The AWS Well-Architected Framework Lens provides a set of foundational questions for you to consider for all of your cloud architectures. Serverless Lens Description The AWS Serverless Application Lens provides a set of additional questions for you to consider for your serverless applications.
  11. Tell how you open AWS console, add workload, grouped questions, download a report
  12. Tell how you open AWS console, add workload, grouped questions, download a report
  13. Serverless can gain polarized opinion starting from “use it everywhere, it’s cool!” to “just a hype, I’m good with my Java 5 + tomcat” And this emotional attitude often drives technology selection That’s why this slide is more about myths about serverless than about antipatterns Myth #1: Serverless means “no server and hardware” Servers not have gone you do not manage them only. And sometimes this abstraction leaks – for lambda you need to setup required RAM size Serverless more means “no infrastructure work” – all the infrastructure maintenance is on provider Portability, Vendor lock Myth #2: Serverless == Lambda (AWS Lambda, Azure Functions etc.) As Serverless means “no infrastructure work”, many of services familiar to you are already serverless. AWS S3 for example. Amazon enumerates as serverless such services as S3, SQS, SNS, API Gateway, DynamoDB Even modification of Aurora falls into this category Myth #3: Serverless is cheap, definitely cheaper than serverfull solution Not always, you always should calculate costs ahead to see if it’s good fit Not all workloads are suitable for serverless Example from Insurance domain, predictable load Ad tech, stock exchange – could bad domain example
  14. The Sirens & Odysseus Antipattern #1: Going stateful (in-memory state) We are not talking about state saved in external service (caches like Redis, databases etc) – that approach is fine But accumulating in-memory state is definitely antipattern: Though lambda instance can be preserved for the next requests (such called “hot start”), it is not guaranteed After lambda run, lambda instance can be terminated anytime So the pattern is: if you need a state, store it in external services. For fast access use distributed caches as AWS ElastiCache (managed Redis) You CAN go with in-memory state if you know what you are doing (lambdas are in warm state, have provisioned/reserved concurrency on – so instances will likely be reused)
  15. Icarus
  16. Myth of Jason and the Argonauts Antipattern #3: Use your favorite tech stack without paying attention at cost “I will write this on Spring Boot” can have such downsides: You might need more memory for lambda than for the same logic written in Go or Python (up to 4 times and more) Startup can be much slower in comparison to using plain old java or another language Can be mitigated by keeping lambda at warm state for hot start Often for cold start the startup time can be longer than processing time itself Both memory size and startup time add a cost You are charged on a second basis. Reducing overall duration from 10 seconds to 5 seconds will cut your costs twice Decreasing memory size (because code in Java was rewritten in Go) by two times will cut your costs twice As lambda should be small, you can write it in Go/Python/JavaScript even if you are not a Pro in this language So the pattern is: consider if the cost benefit worth learning a bit of Python No Dependency Injection frameworks?
  17. King Midas and his touch Antipattern #4: Using old-fashioned way for orchestration “I will save a record in DynamoDB from lambda and then Thread.sleep for another service to update it’s status” Each second if lambda does not do anything, you still pay money Design for retries So the pattern is: Avoid explicit and try to avoid implicit waits Implicit wait – blocking lambda instance awaiting for response from synchronous calls (RESTs) Explicit wait – Thread.sleep, polling messages from queues in while loops, checking state in while loops etc. Use Cloud-Native way of logic organization: Orchestration using AWS Step Functions choreography using message brokers (SQS, EventBridge, Kinesis, DynamoDB Streams)
  18. Nested Stacks Monorepo – one repo for workload Good to keep order, atomic deployments, PR in one repo, easier engennering best practices
  19. 11. AWS Account strategy (Sizing (Account per Team), sharing resources, hard to performance test, limits) a. See Laura's Blog for some details on Lambda Concurrency issues :https://myconnections.lmig.com/blogs/n0085283/2019/03/14/aws-lambdas-setting-a-max-concurrency-its-consequences Best practices: - Dashboards Alerts, Notifications Sets of best practices
  20. Nested Stacks