SlideShare une entreprise Scribd logo
1  sur  32
Télécharger pour lire hors ligne
AWS Lambda Deployments
Best Practices and Common Mistakes
Given by Derek C. Ashmore
November 14, 2016
©2016 Derek C. Ashmore, All Rights Reserved 1
Who am I?
• Professional Geek
since 1987
• Java/J2EE/Java EE
since 1999
• Cloud since 2012
• Roles include:
• Architect
• Developer
• Project Manager
• DBA
• System Admin
©2016 Derek C. Ashmore, All Rights Reserved 2
Discussion Resources
• This slide deck
– http://www.slideshare.net/derekashmore
• Sample code on my Github
– https://github.com/Derek-Ashmore/
• Sample Java AWS Lambda Source
– https://github.com/Derek-Ashmore/AWSLambdaExamples
• Slide deck has hyper-links!
– Don’t bother writing down URLs
©2016 Derek C. Ashmore, All Rights Reserved 3
Agenda
The
“What”
and “Why”
of AWS
Lambda
Developing
Lambda
Deploying
Lambda
Tales from
the Field
Summary /
Q&A
©2016 Derek C. Ashmore, All Rights Reserved 4
What are AWS Lambdas?
• You provide custom code -> AWS runs it
– Java, Node.js, Python
• Computing power with less management
– AWS manages the hardware
– AWS autoscales that hardware
– AWS maintains that hardware
• Lambdas are event driven
– API Gateway (e.g. RESTful Web Service call)
– Many more
• Lambdas are stateless
• Not to be confused with “Lambda Expressions” in Java 8
©2016 Derek C. Ashmore, All Rights Reserved 5
Lambda Event Sources
• API Gateway
• SNS Messaging
Subscriptions
• Schedule
• Storage writes
– S3, DynamoDB, Kenesis
©2016 Derek C. Ashmore, All Rights Reserved 6
• SES Email receipt
• Cloudwatch
– Schedule, Events, log entries
• Cognito (Security)
• CloudFormation
– Creation script
What’s the Business Benefit
• Less Maintenance Hassle
• Unlimited Parallelism
• Current cost advantage
– Don’t pay for idle
– CPU cost currently lower
• Free tier
– 1 M executions and 400K compute seconds per month
– Memory allocated determines allowed free-tier runtime
• 20 cents per 1 M executions + memory/runtime cost
– Administration cost
• No O/S upgrades, server backups, etc.
©2016 Derek C. Ashmore, All Rights Reserved 7
There’s no free lunch
• Less control over environment
– Harder to tune
– Memory and time limits on execution
• Few Environment amenities
– No connection pooling, session support, caching
• Proprietary Interface
– Potential Technical Lock-in
• No Guarantee that AWS cost will be constant
– Potential Business Risk
• Modern version of CGI
©2016 Derek C. Ashmore, All Rights Reserved 8
Lambda Competitors
• Azure Functions (here)
– Closest matching feature set
• Large number of event types
• Node.js and C# Language Support
– Claim to support more, but not documented
• Pricing Model Similar
• Better developer support (IDE integrated with portal)
• Google Cloud Functions (here)
– Still Alpha
– Fewer event types
– Node.js language support
©2016 Derek C. Ashmore, All Rights Reserved 9
Agenda
The
“What”
and “Why”
of AWS
Lambda
Developing
Lambda
Deploying
Lambda
Tales from
the Field
Summary /
Q&A
©2016 Derek C. Ashmore, All Rights Reserved 10
Lambda API
• Create a Request Handler
– Inputs are
• Event input (user input arguments)
• Context input (info about execution environment)
– Outputs are user decided
• JSON marshalling of Request and Response
• Execution Context
• Deployment Zip Artifact
– Typically one RequestHandler per Zip artifact
©2016 Derek C. Ashmore, All Rights Reserved 11
Lambda Request / Response Sample
• Expose REST API that collects email addresses
for a mailing list
– https://scrubbed/prod/EmailCollector
• Sample request/response
©2016 Derek C. Ashmore, All Rights Reserved 12
Java Request Handler Example
• RequestHandler interface is generic.
– POJOs represent the request and response
– POJOs determine JSON request/response format
– Execution Context class provided by AWS
• This class specified when Lambda defined
• Note the wrapping try/catch
– Portion of the Context provided by AWS -> need more
– AWS Does marshalling
– ContextedRuntimeException from Apache Commons Lang3
• Note that the Lambda is thin -> Business logic is elsewhere
• Sample is on GitHub (here)
• Node.js and Python similar
©2016 Derek C. Ashmore, All Rights Reserved 13
What’s in the Context?
• Execution Context provided by AWS
• Contains:
– AWS Request ID -> Get logs for specific request
– Function name, version, arn
– Cognito identity
– Remaining time/memory
– Mobile client information (AWS Mobile SDK)
• Environment name/value map
• Custom name/value map
©2016 Derek C. Ashmore, All Rights Reserved 14
Resource Support
• Runtime Support
– you can configure memory and max run time available
– Java  Java 8; AWS SDK jar must be included in your deployment
– Node.js  AWS SDK for Node.js preinstalled
– Python  AWS SDK for Python preinstalled
• All logging viewable/searchable in Cloudwatch logs
– Node.js and Python log to the console
– Java uses customer Log4J Appender
• Third party jars/libraries can be included
– Including AWS SDK for AWS Tasks (executing other Lambdas)
– Database Drivers
– Web service libraries
• Keep in Mind
– You create/destroy all database connections
• No connection pooling (Lambdas are stateless)
– Caching APIs have limited benefit (Lambdas are stateless)
– No Remote Debug capability
©2016 Derek C. Ashmore, All Rights Reserved 15
Agenda
The
“What”
and “Why”
of AWS
Lambda
Developing
Lambda
Deploying
Lambda
Tales from
the Field
Summary /
Q&A
©2016 Derek C. Ashmore, All Rights Reserved 16
Lambda Deployment Package
• Zip Organization (Java example)
– Root is in the classpath
– Lib contains 3rd party jars
• Maven example here
– Need maven-dependency-plugin, maven-antrun-plugin
©2016 Derek C. Ashmore, All Rights Reserved 17
API Gateway
• Exposes Lambdas as a RESTful Web Service
– Can be publicly available or part of a secured
private microservice library
©2016 Derek C. Ashmore, All Rights Reserved 18
Gateway Lambda Integration
©2016 Derek C. Ashmore, All Rights Reserved 19
• Integrations do basic transformations
– Map headers and parameters to Lambda request
fields
Gateway Integration Example
©2016 Derek C. Ashmore, All Rights Reserved 20
Lambdas and SNS Topics
• Lambdas can subscribe to SNS Publish/subscribe
topics
• Request Message is type SNSEvent
©2016 Derek C. Ashmore, All Rights Reserved 21
Lambdas can be scheduled
• Lambda executions can be scheduled through
CloudWatch
– Cron expressions supported
©2016 Derek C. Ashmore, All Rights Reserved 22
Agenda
The
“What”
and “Why”
of AWS
Lambda
Developing
Lambda
Deploying
Lambda
Tales from
the Field
Summary /
Q&A
©2016 Derek C. Ashmore, All Rights Reserved 23
Chief Complaints
• Documentation leaves a lot to be desired
– This is an understatement.
– For Java Lambdas, you are almost on your own.
• Lambda start-up time not consistent
– Sometimes long start-up time for JVM
– Python is the fastest
• Optimizations that depend on state aren’t as easy
– You would have to persist that state
• This would have it’s own concurrency and performance issues
©2016 Derek C. Ashmore, All Rights Reserved 24
Implementation Tips
• Separation of Concerns
– Keep Lambda code separate from business logic
• Might want to change vendors someday
– Keep AWS SDK code separate from business logic
• Same reason
– Invoke other Lambdas through the API Gateway, not directly through the AWS SDK
• Same reason
– Keep Business Logic locally runnable/debuggable
• Remote debug isn’t yet possible
• Ensure you can always tie AWS Request Id to your business transaction
– Need a way to gather logs from a complete business transactions and the many services it might use
– All invocations get unique AWS request Ids
• For example, lambda invokes other lambdas
– Configure log4j layout (Java) to include AWS Request Id (example)
– Node.js and Python logs have request id automatically
©2016 Derek C. Ashmore, All Rights Reserved 25
Common Use Cases
• Processing for uploaded data
– Image processing
• Low-volume web site features
– Paying for idle cost prohibitive
• Scheduled Batch Work
– Break up batch by invoking other Lambdas
– The resulting scaling is delegated to AWS
©2016 Derek C. Ashmore, All Rights Reserved 26
Performance
• Start-up Time – Python, Node.js, Java
– Berezovsky performance test
• Throughput – Java and Node.js
– Both have a JIT
– DZone comparison here
– Close enough that other factors would likely guide your language
choice
©2016 Derek C. Ashmore, All Rights Reserved 27
Lambdas and Microservices
©2016 Derek C. Ashmore, All Rights Reserved 28
Using Lambdas as Microservices
• Lambda / API Gateway is a deployment option for microservices
– No differences in design principles
• Single purpose
• Self-contained
– Still design for failure
• Don’t “assume” that Lambda outages can’t happen
– A Lambda might need external resources that aren’t available
• Off Limits: Coding patterns that use state
– Lambdas must be stateless
– Fail fast patterns
• Service Call Mediator
• Circuit Breaker
– Performance Patterns
• Expiring Cache (API Gateway allows request caching)
©2016 Derek C. Ashmore, All Rights Reserved 29
Lambda and the Gartner Hype Cycle
©2016 Derek C. Ashmore, All Rights Reserved 30
Further Reading
• This slide deck
– http://www.slideshare.net/derekashmore
• AWS Lambda Reading List
– http://www.derekashmore.com/2016/04/aws-lambda-reading-list.html
©2016 Derek C. Ashmore, All Rights Reserved 31
Questions?
• Derek Ashmore:
– Blog: www.derekashmore.com
– LinkedIn: www.linkedin.com/in/derekashmore
– Twitter: https://twitter.com/Derek_Ashmore
– GitHub: https://github.com/Derek-Ashmore
– Book: http://dvtpress.com/
©2016 Derek C. Ashmore, All Rights Reserved 32

Contenu connexe

Tendances

Writing microservices in Java -- Chicago-2015-11-10
Writing microservices in Java -- Chicago-2015-11-10Writing microservices in Java -- Chicago-2015-11-10
Writing microservices in Java -- Chicago-2015-11-10Derek Ashmore
 
Writing microservices in java java one-2015-10-28
Writing microservices in java java one-2015-10-28Writing microservices in java java one-2015-10-28
Writing microservices in java java one-2015-10-28Derek Ashmore
 
Refactoring Into Microservices. Chicago Coders Conference 2017-06-26
Refactoring Into Microservices. Chicago Coders Conference 2017-06-26Refactoring Into Microservices. Chicago Coders Conference 2017-06-26
Refactoring Into Microservices. Chicago Coders Conference 2017-06-26Derek Ashmore
 
Microservices with Terraform, Docker and the Cloud. DevOps Wet 2018
Microservices with Terraform, Docker and the Cloud. DevOps Wet 2018Microservices with Terraform, Docker and the Cloud. DevOps Wet 2018
Microservices with Terraform, Docker and the Cloud. DevOps Wet 2018Derek Ashmore
 
Microservices for java architects it-symposium-2015-09-15
Microservices for java architects it-symposium-2015-09-15Microservices for java architects it-symposium-2015-09-15
Microservices for java architects it-symposium-2015-09-15Derek Ashmore
 
Serverless in Java Lessons learnt
Serverless in Java Lessons learntServerless in Java Lessons learnt
Serverless in Java Lessons learntKrzysztof Pawlowski
 
High Availability Perl DBI + MySQL
High Availability Perl DBI + MySQLHigh Availability Perl DBI + MySQL
High Availability Perl DBI + MySQLSteve Purkis
 
Microservices for java architects schamburg-2015-05-19
Microservices for java architects schamburg-2015-05-19Microservices for java architects schamburg-2015-05-19
Microservices for java architects schamburg-2015-05-19Derek Ashmore
 
Microservices with Terraform, Docker and the Cloud. JavaOne 2017 2017-10-02
Microservices with Terraform, Docker and the Cloud. JavaOne 2017 2017-10-02Microservices with Terraform, Docker and the Cloud. JavaOne 2017 2017-10-02
Microservices with Terraform, Docker and the Cloud. JavaOne 2017 2017-10-02Derek Ashmore
 
Peeling back the Lambda layers
Peeling back the Lambda layersPeeling back the Lambda layers
Peeling back the Lambda layersPatrick McCaffrey
 
Journey towards serverless infrastructure
Journey towards serverless infrastructureJourney towards serverless infrastructure
Journey towards serverless infrastructureVille Seppänen
 
Scala in the Wild
Scala in the WildScala in the Wild
Scala in the WildTomer Gabel
 
AWS Re:Invent - High Availability Architecture at Netflix
AWS Re:Invent - High Availability Architecture at NetflixAWS Re:Invent - High Availability Architecture at Netflix
AWS Re:Invent - High Availability Architecture at NetflixAdrian Cockcroft
 
Multi-container Applications on OpenShift with Ansible Service Broker
Multi-container Applications on OpenShift with Ansible Service BrokerMulti-container Applications on OpenShift with Ansible Service Broker
Multi-container Applications on OpenShift with Ansible Service BrokerAmazon Web Services
 
Combining R With Java For Data Analysis (Devoxx UK 2015 Session)
Combining R With Java For Data Analysis (Devoxx UK 2015 Session)Combining R With Java For Data Analysis (Devoxx UK 2015 Session)
Combining R With Java For Data Analysis (Devoxx UK 2015 Session)Ryan Cuprak
 
Mcknight well built extensions
Mcknight well built extensionsMcknight well built extensions
Mcknight well built extensionsRichard McKnight
 

Tendances (20)

Writing microservices in Java -- Chicago-2015-11-10
Writing microservices in Java -- Chicago-2015-11-10Writing microservices in Java -- Chicago-2015-11-10
Writing microservices in Java -- Chicago-2015-11-10
 
Writing microservices in java java one-2015-10-28
Writing microservices in java java one-2015-10-28Writing microservices in java java one-2015-10-28
Writing microservices in java java one-2015-10-28
 
Refactoring Into Microservices. Chicago Coders Conference 2017-06-26
Refactoring Into Microservices. Chicago Coders Conference 2017-06-26Refactoring Into Microservices. Chicago Coders Conference 2017-06-26
Refactoring Into Microservices. Chicago Coders Conference 2017-06-26
 
Microservices with Terraform, Docker and the Cloud. DevOps Wet 2018
Microservices with Terraform, Docker and the Cloud. DevOps Wet 2018Microservices with Terraform, Docker and the Cloud. DevOps Wet 2018
Microservices with Terraform, Docker and the Cloud. DevOps Wet 2018
 
Microservices for java architects it-symposium-2015-09-15
Microservices for java architects it-symposium-2015-09-15Microservices for java architects it-symposium-2015-09-15
Microservices for java architects it-symposium-2015-09-15
 
Serverless in Java Lessons learnt
Serverless in Java Lessons learntServerless in Java Lessons learnt
Serverless in Java Lessons learnt
 
High Availability Perl DBI + MySQL
High Availability Perl DBI + MySQLHigh Availability Perl DBI + MySQL
High Availability Perl DBI + MySQL
 
Microservices for java architects schamburg-2015-05-19
Microservices for java architects schamburg-2015-05-19Microservices for java architects schamburg-2015-05-19
Microservices for java architects schamburg-2015-05-19
 
Sas 2015 event_driven
Sas 2015 event_drivenSas 2015 event_driven
Sas 2015 event_driven
 
DevOpsCon Cloud Workshop
DevOpsCon Cloud Workshop DevOpsCon Cloud Workshop
DevOpsCon Cloud Workshop
 
Microservices with Terraform, Docker and the Cloud. JavaOne 2017 2017-10-02
Microservices with Terraform, Docker and the Cloud. JavaOne 2017 2017-10-02Microservices with Terraform, Docker and the Cloud. JavaOne 2017 2017-10-02
Microservices with Terraform, Docker and the Cloud. JavaOne 2017 2017-10-02
 
Docker in the Cloud
Docker in the CloudDocker in the Cloud
Docker in the Cloud
 
Peeling back the Lambda layers
Peeling back the Lambda layersPeeling back the Lambda layers
Peeling back the Lambda layers
 
Journey towards serverless infrastructure
Journey towards serverless infrastructureJourney towards serverless infrastructure
Journey towards serverless infrastructure
 
Scala in the Wild
Scala in the WildScala in the Wild
Scala in the Wild
 
Why akka
Why akkaWhy akka
Why akka
 
AWS Re:Invent - High Availability Architecture at Netflix
AWS Re:Invent - High Availability Architecture at NetflixAWS Re:Invent - High Availability Architecture at Netflix
AWS Re:Invent - High Availability Architecture at Netflix
 
Multi-container Applications on OpenShift with Ansible Service Broker
Multi-container Applications on OpenShift with Ansible Service BrokerMulti-container Applications on OpenShift with Ansible Service Broker
Multi-container Applications on OpenShift with Ansible Service Broker
 
Combining R With Java For Data Analysis (Devoxx UK 2015 Session)
Combining R With Java For Data Analysis (Devoxx UK 2015 Session)Combining R With Java For Data Analysis (Devoxx UK 2015 Session)
Combining R With Java For Data Analysis (Devoxx UK 2015 Session)
 
Mcknight well built extensions
Mcknight well built extensionsMcknight well built extensions
Mcknight well built extensions
 

Similaire à AWS Lambda Best Practices

AWS Lambda: Best Practices and Common Mistakes - Chicago Cloud Conference 2020
AWS Lambda: Best Practices and Common Mistakes - Chicago Cloud Conference 2020AWS Lambda: Best Practices and Common Mistakes - Chicago Cloud Conference 2020
AWS Lambda: Best Practices and Common Mistakes - Chicago Cloud Conference 2020Derek Ashmore
 
AWS Lambda: Best Practices and Common Mistakes - Chicago Cloud Conference 2019
AWS Lambda: Best Practices and Common Mistakes - Chicago Cloud Conference 2019AWS Lambda: Best Practices and Common Mistakes - Chicago Cloud Conference 2019
AWS Lambda: Best Practices and Common Mistakes - Chicago Cloud Conference 2019Derek Ashmore
 
AWS Lambda: Best Practices and Common Mistakes - Dev Ops West 2019
AWS Lambda: Best Practices and Common Mistakes - Dev Ops West 2019AWS Lambda: Best Practices and Common Mistakes - Dev Ops West 2019
AWS Lambda: Best Practices and Common Mistakes - Dev Ops West 2019Derek Ashmore
 
AWS Lambda: Best Practices and Common Mistakes - DevOps East 2019
AWS Lambda: Best Practices and Common Mistakes - DevOps East 2019AWS Lambda: Best Practices and Common Mistakes - DevOps East 2019
AWS Lambda: Best Practices and Common Mistakes - DevOps East 2019Derek Ashmore
 
AWS Community Day - Derek C. Ashmore - AWS Lambda: Best Practices
AWS Community Day  - Derek C. Ashmore - AWS Lambda: Best Practices AWS Community Day  - Derek C. Ashmore - AWS Lambda: Best Practices
AWS Community Day - Derek C. Ashmore - AWS Lambda: Best Practices AWS Chicago
 
AWS Lambda: Best Practices and Common Mistakes - AWS Community Days 2019
AWS Lambda: Best Practices and Common Mistakes - AWS Community Days 2019AWS Lambda: Best Practices and Common Mistakes - AWS Community Days 2019
AWS Lambda: Best Practices and Common Mistakes - AWS Community Days 2019Derek Ashmore
 
Aws lambda best practices - ignite - dev opsdays-charlotte
Aws lambda   best practices - ignite - dev opsdays-charlotteAws lambda   best practices - ignite - dev opsdays-charlotte
Aws lambda best practices - ignite - dev opsdays-charlotteDerek Ashmore
 
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...Amazon Web Services
 
SoCal NodeJS Meetup 20170215_aws_lambda
SoCal NodeJS Meetup 20170215_aws_lambdaSoCal NodeJS Meetup 20170215_aws_lambda
SoCal NodeJS Meetup 20170215_aws_lambdaStefan Deusch
 
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 workloadsTensult
 
AWSomeDay Zurich 2018 - How to go serverless
AWSomeDay Zurich 2018 - How to go serverless AWSomeDay Zurich 2018 - How to go serverless
AWSomeDay Zurich 2018 - How to go serverless Roman Plessl
 
What's New in AWS Serverless and Containers
What's New in AWS Serverless and ContainersWhat's New in AWS Serverless and Containers
What's New in AWS Serverless and ContainersAmazon Web Services
 
An Azure Primer for the AWS Solution Architect - DevOps West 2020
An Azure Primer for the AWS Solution Architect - DevOps West 2020An Azure Primer for the AWS Solution Architect - DevOps West 2020
An Azure Primer for the AWS Solution Architect - DevOps West 2020Derek Ashmore
 
AWS re:Invent 2016: Accenture Cloud Platform Serverless Journey (ARC202)
AWS re:Invent 2016: Accenture Cloud Platform Serverless Journey (ARC202)AWS re:Invent 2016: Accenture Cloud Platform Serverless Journey (ARC202)
AWS re:Invent 2016: Accenture Cloud Platform Serverless Journey (ARC202)Amazon Web Services
 
Deep Dive on AWS Lambda - January 2017 AWS Online Tech Talks
Deep Dive on AWS Lambda - January 2017 AWS Online Tech TalksDeep Dive on AWS Lambda - January 2017 AWS Online Tech Talks
Deep Dive on AWS Lambda - January 2017 AWS Online Tech TalksAmazon Web Services
 
Serverless Architecture Patterns
Serverless Architecture PatternsServerless Architecture Patterns
Serverless Architecture PatternsAmazon Web Services
 
Developing serverless applications with .NET on AWS
Developing serverless applications with .NET on AWSDeveloping serverless applications with .NET on AWS
Developing serverless applications with .NET on AWSWoody Pewitt
 
Serverless in java Lessons learnt
Serverless in java Lessons learntServerless in java Lessons learnt
Serverless in java Lessons learntKrzysztof Pawlowski
 
Serverless Computing
Serverless ComputingServerless Computing
Serverless ComputingAnand Gupta
 

Similaire à AWS Lambda Best Practices (20)

AWS Lambda: Best Practices and Common Mistakes - Chicago Cloud Conference 2020
AWS Lambda: Best Practices and Common Mistakes - Chicago Cloud Conference 2020AWS Lambda: Best Practices and Common Mistakes - Chicago Cloud Conference 2020
AWS Lambda: Best Practices and Common Mistakes - Chicago Cloud Conference 2020
 
AWS Lambda: Best Practices and Common Mistakes - Chicago Cloud Conference 2019
AWS Lambda: Best Practices and Common Mistakes - Chicago Cloud Conference 2019AWS Lambda: Best Practices and Common Mistakes - Chicago Cloud Conference 2019
AWS Lambda: Best Practices and Common Mistakes - Chicago Cloud Conference 2019
 
AWS Lambda: Best Practices and Common Mistakes - Dev Ops West 2019
AWS Lambda: Best Practices and Common Mistakes - Dev Ops West 2019AWS Lambda: Best Practices and Common Mistakes - Dev Ops West 2019
AWS Lambda: Best Practices and Common Mistakes - Dev Ops West 2019
 
AWS Lambda: Best Practices and Common Mistakes - DevOps East 2019
AWS Lambda: Best Practices and Common Mistakes - DevOps East 2019AWS Lambda: Best Practices and Common Mistakes - DevOps East 2019
AWS Lambda: Best Practices and Common Mistakes - DevOps East 2019
 
AWS Community Day - Derek C. Ashmore - AWS Lambda: Best Practices
AWS Community Day  - Derek C. Ashmore - AWS Lambda: Best Practices AWS Community Day  - Derek C. Ashmore - AWS Lambda: Best Practices
AWS Community Day - Derek C. Ashmore - AWS Lambda: Best Practices
 
AWS Lambda: Best Practices and Common Mistakes - AWS Community Days 2019
AWS Lambda: Best Practices and Common Mistakes - AWS Community Days 2019AWS Lambda: Best Practices and Common Mistakes - AWS Community Days 2019
AWS Lambda: Best Practices and Common Mistakes - AWS Community Days 2019
 
Aws lambda best practices - ignite - dev opsdays-charlotte
Aws lambda   best practices - ignite - dev opsdays-charlotteAws lambda   best practices - ignite - dev opsdays-charlotte
Aws lambda best practices - ignite - dev opsdays-charlotte
 
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...
 
SoCal NodeJS Meetup 20170215_aws_lambda
SoCal NodeJS Meetup 20170215_aws_lambdaSoCal NodeJS Meetup 20170215_aws_lambda
SoCal NodeJS Meetup 20170215_aws_lambda
 
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
 
AWSomeDay Zurich 2018 - How to go serverless
AWSomeDay Zurich 2018 - How to go serverless AWSomeDay Zurich 2018 - How to go serverless
AWSomeDay Zurich 2018 - How to go serverless
 
What's New in AWS Serverless and Containers
What's New in AWS Serverless and ContainersWhat's New in AWS Serverless and Containers
What's New in AWS Serverless and Containers
 
An Azure Primer for the AWS Solution Architect - DevOps West 2020
An Azure Primer for the AWS Solution Architect - DevOps West 2020An Azure Primer for the AWS Solution Architect - DevOps West 2020
An Azure Primer for the AWS Solution Architect - DevOps West 2020
 
AWS re:Invent 2016: Accenture Cloud Platform Serverless Journey (ARC202)
AWS re:Invent 2016: Accenture Cloud Platform Serverless Journey (ARC202)AWS re:Invent 2016: Accenture Cloud Platform Serverless Journey (ARC202)
AWS re:Invent 2016: Accenture Cloud Platform Serverless Journey (ARC202)
 
Deep Dive on AWS Lambda - January 2017 AWS Online Tech Talks
Deep Dive on AWS Lambda - January 2017 AWS Online Tech TalksDeep Dive on AWS Lambda - January 2017 AWS Online Tech Talks
Deep Dive on AWS Lambda - January 2017 AWS Online Tech Talks
 
Serverless Architecture Patterns
Serverless Architecture PatternsServerless Architecture Patterns
Serverless Architecture Patterns
 
Developing serverless applications with .NET on AWS
Developing serverless applications with .NET on AWSDeveloping serverless applications with .NET on AWS
Developing serverless applications with .NET on AWS
 
Serverless in java Lessons learnt
Serverless in java Lessons learntServerless in java Lessons learnt
Serverless in java Lessons learnt
 
Serverless Computing
Serverless ComputingServerless Computing
Serverless Computing
 
Deep Dive on AWS Lambda
Deep Dive on AWS LambdaDeep Dive on AWS Lambda
Deep Dive on AWS Lambda
 

Dernier

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 

Dernier (20)

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 

AWS Lambda Best Practices

  • 1. AWS Lambda Deployments Best Practices and Common Mistakes Given by Derek C. Ashmore November 14, 2016 ©2016 Derek C. Ashmore, All Rights Reserved 1
  • 2. Who am I? • Professional Geek since 1987 • Java/J2EE/Java EE since 1999 • Cloud since 2012 • Roles include: • Architect • Developer • Project Manager • DBA • System Admin ©2016 Derek C. Ashmore, All Rights Reserved 2
  • 3. Discussion Resources • This slide deck – http://www.slideshare.net/derekashmore • Sample code on my Github – https://github.com/Derek-Ashmore/ • Sample Java AWS Lambda Source – https://github.com/Derek-Ashmore/AWSLambdaExamples • Slide deck has hyper-links! – Don’t bother writing down URLs ©2016 Derek C. Ashmore, All Rights Reserved 3
  • 4. Agenda The “What” and “Why” of AWS Lambda Developing Lambda Deploying Lambda Tales from the Field Summary / Q&A ©2016 Derek C. Ashmore, All Rights Reserved 4
  • 5. What are AWS Lambdas? • You provide custom code -> AWS runs it – Java, Node.js, Python • Computing power with less management – AWS manages the hardware – AWS autoscales that hardware – AWS maintains that hardware • Lambdas are event driven – API Gateway (e.g. RESTful Web Service call) – Many more • Lambdas are stateless • Not to be confused with “Lambda Expressions” in Java 8 ©2016 Derek C. Ashmore, All Rights Reserved 5
  • 6. Lambda Event Sources • API Gateway • SNS Messaging Subscriptions • Schedule • Storage writes – S3, DynamoDB, Kenesis ©2016 Derek C. Ashmore, All Rights Reserved 6 • SES Email receipt • Cloudwatch – Schedule, Events, log entries • Cognito (Security) • CloudFormation – Creation script
  • 7. What’s the Business Benefit • Less Maintenance Hassle • Unlimited Parallelism • Current cost advantage – Don’t pay for idle – CPU cost currently lower • Free tier – 1 M executions and 400K compute seconds per month – Memory allocated determines allowed free-tier runtime • 20 cents per 1 M executions + memory/runtime cost – Administration cost • No O/S upgrades, server backups, etc. ©2016 Derek C. Ashmore, All Rights Reserved 7
  • 8. There’s no free lunch • Less control over environment – Harder to tune – Memory and time limits on execution • Few Environment amenities – No connection pooling, session support, caching • Proprietary Interface – Potential Technical Lock-in • No Guarantee that AWS cost will be constant – Potential Business Risk • Modern version of CGI ©2016 Derek C. Ashmore, All Rights Reserved 8
  • 9. Lambda Competitors • Azure Functions (here) – Closest matching feature set • Large number of event types • Node.js and C# Language Support – Claim to support more, but not documented • Pricing Model Similar • Better developer support (IDE integrated with portal) • Google Cloud Functions (here) – Still Alpha – Fewer event types – Node.js language support ©2016 Derek C. Ashmore, All Rights Reserved 9
  • 10. Agenda The “What” and “Why” of AWS Lambda Developing Lambda Deploying Lambda Tales from the Field Summary / Q&A ©2016 Derek C. Ashmore, All Rights Reserved 10
  • 11. Lambda API • Create a Request Handler – Inputs are • Event input (user input arguments) • Context input (info about execution environment) – Outputs are user decided • JSON marshalling of Request and Response • Execution Context • Deployment Zip Artifact – Typically one RequestHandler per Zip artifact ©2016 Derek C. Ashmore, All Rights Reserved 11
  • 12. Lambda Request / Response Sample • Expose REST API that collects email addresses for a mailing list – https://scrubbed/prod/EmailCollector • Sample request/response ©2016 Derek C. Ashmore, All Rights Reserved 12
  • 13. Java Request Handler Example • RequestHandler interface is generic. – POJOs represent the request and response – POJOs determine JSON request/response format – Execution Context class provided by AWS • This class specified when Lambda defined • Note the wrapping try/catch – Portion of the Context provided by AWS -> need more – AWS Does marshalling – ContextedRuntimeException from Apache Commons Lang3 • Note that the Lambda is thin -> Business logic is elsewhere • Sample is on GitHub (here) • Node.js and Python similar ©2016 Derek C. Ashmore, All Rights Reserved 13
  • 14. What’s in the Context? • Execution Context provided by AWS • Contains: – AWS Request ID -> Get logs for specific request – Function name, version, arn – Cognito identity – Remaining time/memory – Mobile client information (AWS Mobile SDK) • Environment name/value map • Custom name/value map ©2016 Derek C. Ashmore, All Rights Reserved 14
  • 15. Resource Support • Runtime Support – you can configure memory and max run time available – Java  Java 8; AWS SDK jar must be included in your deployment – Node.js  AWS SDK for Node.js preinstalled – Python  AWS SDK for Python preinstalled • All logging viewable/searchable in Cloudwatch logs – Node.js and Python log to the console – Java uses customer Log4J Appender • Third party jars/libraries can be included – Including AWS SDK for AWS Tasks (executing other Lambdas) – Database Drivers – Web service libraries • Keep in Mind – You create/destroy all database connections • No connection pooling (Lambdas are stateless) – Caching APIs have limited benefit (Lambdas are stateless) – No Remote Debug capability ©2016 Derek C. Ashmore, All Rights Reserved 15
  • 16. Agenda The “What” and “Why” of AWS Lambda Developing Lambda Deploying Lambda Tales from the Field Summary / Q&A ©2016 Derek C. Ashmore, All Rights Reserved 16
  • 17. Lambda Deployment Package • Zip Organization (Java example) – Root is in the classpath – Lib contains 3rd party jars • Maven example here – Need maven-dependency-plugin, maven-antrun-plugin ©2016 Derek C. Ashmore, All Rights Reserved 17
  • 18. API Gateway • Exposes Lambdas as a RESTful Web Service – Can be publicly available or part of a secured private microservice library ©2016 Derek C. Ashmore, All Rights Reserved 18
  • 19. Gateway Lambda Integration ©2016 Derek C. Ashmore, All Rights Reserved 19 • Integrations do basic transformations – Map headers and parameters to Lambda request fields
  • 20. Gateway Integration Example ©2016 Derek C. Ashmore, All Rights Reserved 20
  • 21. Lambdas and SNS Topics • Lambdas can subscribe to SNS Publish/subscribe topics • Request Message is type SNSEvent ©2016 Derek C. Ashmore, All Rights Reserved 21
  • 22. Lambdas can be scheduled • Lambda executions can be scheduled through CloudWatch – Cron expressions supported ©2016 Derek C. Ashmore, All Rights Reserved 22
  • 23. Agenda The “What” and “Why” of AWS Lambda Developing Lambda Deploying Lambda Tales from the Field Summary / Q&A ©2016 Derek C. Ashmore, All Rights Reserved 23
  • 24. Chief Complaints • Documentation leaves a lot to be desired – This is an understatement. – For Java Lambdas, you are almost on your own. • Lambda start-up time not consistent – Sometimes long start-up time for JVM – Python is the fastest • Optimizations that depend on state aren’t as easy – You would have to persist that state • This would have it’s own concurrency and performance issues ©2016 Derek C. Ashmore, All Rights Reserved 24
  • 25. Implementation Tips • Separation of Concerns – Keep Lambda code separate from business logic • Might want to change vendors someday – Keep AWS SDK code separate from business logic • Same reason – Invoke other Lambdas through the API Gateway, not directly through the AWS SDK • Same reason – Keep Business Logic locally runnable/debuggable • Remote debug isn’t yet possible • Ensure you can always tie AWS Request Id to your business transaction – Need a way to gather logs from a complete business transactions and the many services it might use – All invocations get unique AWS request Ids • For example, lambda invokes other lambdas – Configure log4j layout (Java) to include AWS Request Id (example) – Node.js and Python logs have request id automatically ©2016 Derek C. Ashmore, All Rights Reserved 25
  • 26. Common Use Cases • Processing for uploaded data – Image processing • Low-volume web site features – Paying for idle cost prohibitive • Scheduled Batch Work – Break up batch by invoking other Lambdas – The resulting scaling is delegated to AWS ©2016 Derek C. Ashmore, All Rights Reserved 26
  • 27. Performance • Start-up Time – Python, Node.js, Java – Berezovsky performance test • Throughput – Java and Node.js – Both have a JIT – DZone comparison here – Close enough that other factors would likely guide your language choice ©2016 Derek C. Ashmore, All Rights Reserved 27
  • 28. Lambdas and Microservices ©2016 Derek C. Ashmore, All Rights Reserved 28
  • 29. Using Lambdas as Microservices • Lambda / API Gateway is a deployment option for microservices – No differences in design principles • Single purpose • Self-contained – Still design for failure • Don’t “assume” that Lambda outages can’t happen – A Lambda might need external resources that aren’t available • Off Limits: Coding patterns that use state – Lambdas must be stateless – Fail fast patterns • Service Call Mediator • Circuit Breaker – Performance Patterns • Expiring Cache (API Gateway allows request caching) ©2016 Derek C. Ashmore, All Rights Reserved 29
  • 30. Lambda and the Gartner Hype Cycle ©2016 Derek C. Ashmore, All Rights Reserved 30
  • 31. Further Reading • This slide deck – http://www.slideshare.net/derekashmore • AWS Lambda Reading List – http://www.derekashmore.com/2016/04/aws-lambda-reading-list.html ©2016 Derek C. Ashmore, All Rights Reserved 31
  • 32. Questions? • Derek Ashmore: – Blog: www.derekashmore.com – LinkedIn: www.linkedin.com/in/derekashmore – Twitter: https://twitter.com/Derek_Ashmore – GitHub: https://github.com/Derek-Ashmore – Book: http://dvtpress.com/ ©2016 Derek C. Ashmore, All Rights Reserved 32