SlideShare a Scribd company logo
1 of 27
Download to read offline
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Twelve-factor app methodology
and modern applications
Uri Segev
Principal Solutions Architect
Amazon Web Services
D E V 3 0 8
Oren Reuveni
Solutions Architect
Amazon Web Services
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Agenda
• What is the “12 Factor app”?
• What do we mean by “Serverless”?
• 12 Factor in a serverless app
• Demo
• Takeaways
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
The “12 Factor” model & serverless applications
• Methodology for building modern applications
• A popular best practice for both developers and operations engineers
• Many of the 12 Factor guidelines align directly with best practices for
serverless applications and are improved upon given the nature of
AWS Lambda, Amazon API Gateway, and other AWS services
• However, some of the 12 Factor guidelines don’t directly align with
serverless applications or are interpreted very differently
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
What is serverless?
No infrastructure provisioning,
no management
Automatic scaling
Pay for value Highly available and secure
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS Lambda
Run code without provisioning or managing servers
Virtually any type of application or backend service
Trigger from other AWS services or call it directly
from any web or mobile app
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Serverless applications
Services (anything)
Changes in
data state
Requests to
endpoints
Changes in
resource state
Event source Function
Node.js
Python
Java
C#
Go
Ruby
Runtime API
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS
Lambda
AWS
Fargate
COMPUTE
DATA STORES
INTEGRATION
Amazon Aurora
Serverless
Amazon
S3
Amazon
DynamoDB
Amazon
API Gateway
Amazon
SNS
Amazon
SQS
AWS
Step Functions
AWS
AppSync
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
The 12 Factors:
Let’s explore how the 12 Factors apply to a serverless application:
1. Codebase
2. Dependencies
3. Config
4. Backing services
5. Build, release, run
6. Process
7. Port Binding
8. Concurrency
9. Disposability
10. Dev/prod parity
11. Logs
12. Admin processes
https://12factor.net
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
1. Codebase
12Factor: “One codebase tracked in revision control, many deploys”
Serverless Apps: All code should be stored in revision control (a
development best practice).
Same repository should be used for all environments deployed to.
The bounds of an “application” differ in serverless terms:
• If events are shared (i.e., a common Amazon API Gateway) then
Lambda function code for those events should be put in the same
repository
• Otherwise break “services” into their own repositories
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
2. Dependencies
12Factor: “Explicitly declare and isolate dependencies”
Serverless Apps: Code that is used by multiple functions should be
packaged into its own library. Include those libs inside your deployment
package or into a AWS Lambda Layer.
Node.js, Python, Ruby
• Use npm/pip to
install libraries
• All dependencies
must be at root
level
• .zip file consisting of
your code and any
dependencies
Java
• Either .zip file with all
code/dependencies,
or standalone .jar
• Use Maven / Eclipse
IDE plugins
• Compiled class &
resource files at root
level, required jars in
/lib directory
C# (.NET Core)
• Either .zip file with
all code /
dependencies, or a
standalone .dll
• Use NuGet /
VisualStudio
plugins
• All assemblies (.dll)
at root level
Go
• .zip file consisting
of your Go binary
and any
dependencies
• Use “go get” to
install
dependencies
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Lambda Layers
Lets functions easily share code: Upload layer
once, reference within any function
Layer can be anything: dependencies, training
data, configuration files, etc
Promote separation of responsibilities, lets
developers iterate faster on writing business logic
Built in support for secure sharing by ecosystem
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
3. Config
12Factor: “Store config in the environment”
Serverless Apps: Many ways to do this in serverless applications:
• Lambda environment variables
• API Gateway stage variables
• AWS Systems Manager Parameter Store
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
4. Backing services
12Factor: “Treat backing services as attached resources”
Serverless Apps: No differences. Resources that Lambda functions
connect to, such as databases, should have their endpoints and access
credentials made available via config resources or IAM policies
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
5. Build, Release, Run
12Factor: “Strictly separate build and run stages”
Serverless Apps: No differences. Development best practices such as
Continuous Integration and Continuous Delivery should be followed.
• Use AWS CodeBuild and AWS CodePipeline to support this:
AWS CodeBuild AWS CodePipeline
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
CI/CD for serverless applications
• Source code repository hosts SAM template
• CodePipeline per application
• CodeBuild generates a deployable artifact
• CodePipeline/CodeDeploy deploys to
different environments, with the right
config
CodeBuildCodeCommit CodePipeline
CloudFormation
API Gateway
Lambda
Dev account
Step Functions
DynamoDBCodeDeploy
CloudFormation
API Gateway
Lambda
Test account
Step Functions
DynamoDB
CodeDeploy
CloudFormation
API Gateway
Lambda
Prod account
Step Functions
DynamoDB
CodeDeploy
Tools accountCode account
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
6. Process
12Factor: “Execute the app as one or more stateless processes”
Serverless Apps: This is inherent in how Lambda is designed already:
• Lambda Functions should be treated as stateless components
• There is no promise of execution environment re-use between function
invocations
• Data that needs to be kept should be stored in a stateful service such
as a database or cache
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
7. Port binding
12Factor: “Export services via port binding”
Serverless Apps: In Lambda/serverless applications this factor doesn’t
apply the same due to a difference in how Lambda Functions are
accessed:
• Instead of a “port” Lambda functions are invoked by an event
• Lambda functions are invoked in 3 ways: synchronously,
asynchronously, and via stream
• Instead of having one function support multiple invocation sources,
create independent functions
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Lambda execution model
Synchronous (push)
AWS Lambda
function
/order
Asynchronous (event)
AWS Lambda
function
reqs
Poll-based
changes
AWS Lambda
service
Function
Amazon
API Gateway
Amazon
SNS
Amazon
S3
Amazon
DynamoDB
Amazon
Kinesis
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
8. Concurrency
12Factor: “Scale out via the process model”
Serverless Apps: Doesn’t apply. Lambda functions will scale automatically
based on load.
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
9. Disposability
12Factor: “Maximize robustness with fast startup and graceful shutdown”
Serverless Apps:
Shutdown doesn’t apply as Lambda functions and their invocation are
tied directly to incoming events.
Speed at startup does matter:
• Minimize package size to necessities
• Do one thing – smaller package size
• Reuse – initializing clients/instances outside the handler
• Choose the right environment size for optimal operation
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
10. Dev/prod parity
12Factor: “Keep dev, staging, and production as similar as possible”
Serverless Apps: This can be made incredibly easy with serverless
applications by:
• Making use of environment/stage variables or Parameter Store for
configuration information, backend resources, etc
• Using Serverless Application Models (SAM) to deploy your application
• Having a CI/CD process and tooling that supports multiple
environments or accounts
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
11. Logs
12Factor: “Treat logs as event streams”
Serverless Apps: Logging (as well as Metric collection) are considered a
“universal right” in Lambda:
• Console output automatically collected and sent to Amazon
CloudWatch Logs
• Metrics for Lambda and API Gateway for several key stats are
automatically collected and sent to CloudWatch
• You can easily send more using the CloudWatch SDK
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
12. Admin processes
12Factor: “Run admin/management tasks as one-off processes”
Serverless Apps: Doesn’t apply to Lambda since you already limit your
functions based on use case.
True administrative tasks would occur via their own Lambda Functions.
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS Serverless Application Model (SAM)
• AWS CloudFormation extension optimized for
serverless
• Special serverless resource types:
• Functions, APIs, SimpleTables and Layers
• CLI tool for local development, debugging,
testing, deploying, and monitoring of
serverless applications
https://aws.amazon.com/serverless/sam
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Takeaways
• The 12 factor app methodology can assist with designing modern
applications properly
• Many factors are already built into serverless applications
• Serverless applications assist with focusing on our core business
https://aws.amazon.com/serverless/
Thank you!
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Uri Segev
Oren Reuveni
http://bit.ly/2SFkTzT

More Related Content

What's hot

What's hot (19)

Building a fully serverless application on AWS | AWS Summit Tel Aviv 2019
Building a fully serverless application on AWS | AWS Summit Tel Aviv 2019Building a fully serverless application on AWS | AWS Summit Tel Aviv 2019
Building a fully serverless application on AWS | AWS Summit Tel Aviv 2019
 
AWS 如何協助客戶建立 DevOps 流程
AWS 如何協助客戶建立 DevOps 流程AWS 如何協助客戶建立 DevOps 流程
AWS 如何協助客戶建立 DevOps 流程
 
Let Your Business Logic go Serverless | AWS Summit Tel Aviv 2019
 Let Your Business Logic go Serverless | AWS Summit Tel Aviv 2019 Let Your Business Logic go Serverless | AWS Summit Tel Aviv 2019
Let Your Business Logic go Serverless | AWS Summit Tel Aviv 2019
 
How AWS builds Serverless services using Serverless
How AWS builds Serverless services using ServerlessHow AWS builds Serverless services using Serverless
How AWS builds Serverless services using Serverless
 
Serverless - State of the Union
Serverless - State of the UnionServerless - State of the Union
Serverless - State of the Union
 
Building-Modern-Distributed-Applications
Building-Modern-Distributed-ApplicationsBuilding-Modern-Distributed-Applications
Building-Modern-Distributed-Applications
 
Costruisci e distribuisci applicazioni web moderne con AWS Amplify Console
Costruisci e distribuisci applicazioni web moderne con AWS Amplify ConsoleCostruisci e distribuisci applicazioni web moderne con AWS Amplify Console
Costruisci e distribuisci applicazioni web moderne con AWS Amplify Console
 
Intro to AWS Lambda and Serverless Applications: re:Invent 2018 Recap at the ...
Intro to AWS Lambda and Serverless Applications: re:Invent 2018 Recap at the ...Intro to AWS Lambda and Serverless Applications: re:Invent 2018 Recap at the ...
Intro to AWS Lambda and Serverless Applications: re:Invent 2018 Recap at the ...
 
Deep Dive - CI/CD on AWS
Deep Dive - CI/CD on AWSDeep Dive - CI/CD on AWS
Deep Dive - CI/CD on AWS
 
Programming Infrastructure with AWS CDK
Programming Infrastructure with AWS CDKProgramming Infrastructure with AWS CDK
Programming Infrastructure with AWS CDK
 
CI/CD best practices for building modern applications - MAD304 - Chicago AWS ...
CI/CD best practices for building modern applications - MAD304 - Chicago AWS ...CI/CD best practices for building modern applications - MAD304 - Chicago AWS ...
CI/CD best practices for building modern applications - MAD304 - Chicago AWS ...
 
Essential capabilities behind Microservices
Essential capabilities behind MicroservicesEssential capabilities behind Microservices
Essential capabilities behind Microservices
 
Microservices on AWS: Architectural Patterns and Best Practices | AWS Summit ...
Microservices on AWS: Architectural Patterns and Best Practices | AWS Summit ...Microservices on AWS: Architectural Patterns and Best Practices | AWS Summit ...
Microservices on AWS: Architectural Patterns and Best Practices | AWS Summit ...
 
Stages of Adoption leading to Complete Migration
Stages of Adoption leading to Complete Migration	Stages of Adoption leading to Complete Migration
Stages of Adoption leading to Complete Migration
 
Architecting Security & Governance Across Your AWS Landing Zone
Architecting Security & Governance Across Your AWS Landing ZoneArchitecting Security & Governance Across Your AWS Landing Zone
Architecting Security & Governance Across Your AWS Landing Zone
 
From Code to a running container | AWS Summit Tel Aviv 2019
From Code to a running container | AWS Summit Tel Aviv 2019From Code to a running container | AWS Summit Tel Aviv 2019
From Code to a running container | AWS Summit Tel Aviv 2019
 
Serverless is dead.
Serverless is dead.Serverless is dead.
Serverless is dead.
 
Modern Application Development for Startups
Modern Application Development for StartupsModern Application Development for Startups
Modern Application Development for Startups
 
CI/CD Best Practices for Building Modern Applications - MAD302 - Anaheim AWS ...
CI/CD Best Practices for Building Modern Applications - MAD302 - Anaheim AWS ...CI/CD Best Practices for Building Modern Applications - MAD302 - Anaheim AWS ...
CI/CD Best Practices for Building Modern Applications - MAD302 - Anaheim AWS ...
 

Similar to Twelve-Factor App Methodology and Modern Applications | AWS Summit Tel Aviv 2019

Similar to Twelve-Factor App Methodology and Modern Applications | AWS Summit Tel Aviv 2019 (20)

Twelve-Factor serverless applications - MAD311 - Chicago AWS Summit
Twelve-Factor serverless applications - MAD311 - Chicago AWS SummitTwelve-Factor serverless applications - MAD311 - Chicago AWS Summit
Twelve-Factor serverless applications - MAD311 - Chicago AWS Summit
 
Twelve-Factor Serverless Applications - MAD303 - Anaheim AWS Summit
Twelve-Factor Serverless Applications - MAD303 - Anaheim AWS SummitTwelve-Factor Serverless Applications - MAD303 - Anaheim AWS Summit
Twelve-Factor Serverless Applications - MAD303 - Anaheim AWS Summit
 
Twelve-Factor serverless applications - MAD307 - New York AWS Summit
Twelve-Factor serverless applications - MAD307 - New York AWS SummitTwelve-Factor serverless applications - MAD307 - New York AWS Summit
Twelve-Factor serverless applications - MAD307 - New York AWS Summit
 
Serverless Computing: build and run applications without thinking about servers
Serverless Computing: build and run applications without thinking about serversServerless Computing: build and run applications without thinking about servers
Serverless Computing: build and run applications without thinking about servers
 
Build Modern Applications that Align with Twelve-Factor Methods (API303) - AW...
Build Modern Applications that Align with Twelve-Factor Methods (API303) - AW...Build Modern Applications that Align with Twelve-Factor Methods (API303) - AW...
Build Modern Applications that Align with Twelve-Factor Methods (API303) - AW...
 
Let Your Business Logic go Serverless | AWS Summit Tel Aviv 2019
 Let Your Business Logic go Serverless | AWS Summit Tel Aviv 2019 Let Your Business Logic go Serverless | AWS Summit Tel Aviv 2019
Let Your Business Logic go Serverless | AWS Summit Tel Aviv 2019
 
Twelve Factor Serverless Applications
Twelve Factor Serverless ApplicationsTwelve Factor Serverless Applications
Twelve Factor Serverless Applications
 
Twelve-Factor Serverless Applications
Twelve-Factor Serverless ApplicationsTwelve-Factor Serverless Applications
Twelve-Factor Serverless Applications
 
12 Factor Serverless Applications - Mike Morain, AWS - Cloud Native Day Tel A...
12 Factor Serverless Applications - Mike Morain, AWS - Cloud Native Day Tel A...12 Factor Serverless Applications - Mike Morain, AWS - Cloud Native Day Tel A...
12 Factor Serverless Applications - Mike Morain, AWS - Cloud Native Day Tel A...
 
AWS Dev Lounge: Applying the Twelve-Factor Application Manifesto to Developin...
AWS Dev Lounge: Applying the Twelve-Factor Application Manifesto to Developin...AWS Dev Lounge: Applying the Twelve-Factor Application Manifesto to Developin...
AWS Dev Lounge: Applying the Twelve-Factor Application Manifesto to Developin...
 
JFokus 2020 - How to migrate an application to serverless
JFokus 2020 - How to migrate an application to serverlessJFokus 2020 - How to migrate an application to serverless
JFokus 2020 - How to migrate an application to serverless
 
Introduction to Serverless on AWS
Introduction to Serverless on AWSIntroduction to Serverless on AWS
Introduction to Serverless on AWS
 
Introduction to AWS Lambda and Serverless Applications
Introduction to AWS Lambda and Serverless ApplicationsIntroduction to AWS Lambda and Serverless Applications
Introduction to AWS Lambda and Serverless Applications
 
Modern Applications Development on AWS
Modern Applications Development on AWSModern Applications Development on AWS
Modern Applications Development on AWS
 
Serverless: State Of the Union
Serverless: State Of the UnionServerless: State Of the Union
Serverless: State Of the Union
 
Serverless - State Of the Union
Serverless - State Of the UnionServerless - State Of the Union
Serverless - State Of the Union
 
Serverless computing - Build and run applications without thinking about servers
Serverless computing - Build and run applications without thinking about serversServerless computing - Build and run applications without thinking about servers
Serverless computing - Build and run applications without thinking about servers
 
muCon 2017 - 12 Factor Serverless Applications
muCon 2017 - 12 Factor Serverless ApplicationsmuCon 2017 - 12 Factor Serverless Applications
muCon 2017 - 12 Factor Serverless Applications
 
Building APIs with Amazon API Gateway
Building APIs with Amazon API GatewayBuilding APIs with Amazon API Gateway
Building APIs with Amazon API Gateway
 
Building APIs with Amazon API Gateway: re:Invent 2018 Recap at the AWS Loft -...
Building APIs with Amazon API Gateway: re:Invent 2018 Recap at the AWS Loft -...Building APIs with Amazon API Gateway: re:Invent 2018 Recap at the AWS Loft -...
Building APIs with Amazon API Gateway: re:Invent 2018 Recap at the AWS Loft -...
 

More from Amazon Web Services

Tools for building your MVP on AWS
Tools for building your MVP on AWSTools for building your MVP on AWS
Tools for building your MVP on AWS
Amazon Web Services
 
How to Build a Winning Pitch Deck
How to Build a Winning Pitch DeckHow to Build a Winning Pitch Deck
How to Build a Winning Pitch Deck
Amazon Web Services
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without servers
Amazon Web Services
 
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
Amazon Web Services
 

More from Amazon Web Services (20)

Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
 
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
 
Esegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS FargateEsegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS Fargate
 
Costruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWSCostruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWS
 
Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot
 
Open banking as a service
Open banking as a serviceOpen banking as a service
Open banking as a service
 
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
 
OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...
 
Microsoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows WorkloadsMicrosoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows Workloads
 
Computer Vision con AWS
Computer Vision con AWSComputer Vision con AWS
Computer Vision con AWS
 
Database Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatareDatabase Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatare
 
Crea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJSCrea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJS
 
API moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e webAPI moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e web
 
Database Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatareDatabase Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatare
 
Tools for building your MVP on AWS
Tools for building your MVP on AWSTools for building your MVP on AWS
Tools for building your MVP on AWS
 
How to Build a Winning Pitch Deck
How to Build a Winning Pitch DeckHow to Build a Winning Pitch Deck
How to Build a Winning Pitch Deck
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without servers
 
Fundraising Essentials
Fundraising EssentialsFundraising Essentials
Fundraising Essentials
 
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
 
Introduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container ServiceIntroduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container Service
 

Twelve-Factor App Methodology and Modern Applications | AWS Summit Tel Aviv 2019

  • 1. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Twelve-factor app methodology and modern applications Uri Segev Principal Solutions Architect Amazon Web Services D E V 3 0 8 Oren Reuveni Solutions Architect Amazon Web Services
  • 2. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Agenda • What is the “12 Factor app”? • What do we mean by “Serverless”? • 12 Factor in a serverless app • Demo • Takeaways
  • 3. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. The “12 Factor” model & serverless applications • Methodology for building modern applications • A popular best practice for both developers and operations engineers • Many of the 12 Factor guidelines align directly with best practices for serverless applications and are improved upon given the nature of AWS Lambda, Amazon API Gateway, and other AWS services • However, some of the 12 Factor guidelines don’t directly align with serverless applications or are interpreted very differently
  • 4. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. What is serverless? No infrastructure provisioning, no management Automatic scaling Pay for value Highly available and secure
  • 5. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS Lambda Run code without provisioning or managing servers Virtually any type of application or backend service Trigger from other AWS services or call it directly from any web or mobile app
  • 6. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Serverless applications Services (anything) Changes in data state Requests to endpoints Changes in resource state Event source Function Node.js Python Java C# Go Ruby Runtime API
  • 7. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS Lambda AWS Fargate COMPUTE DATA STORES INTEGRATION Amazon Aurora Serverless Amazon S3 Amazon DynamoDB Amazon API Gateway Amazon SNS Amazon SQS AWS Step Functions AWS AppSync
  • 8. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. The 12 Factors: Let’s explore how the 12 Factors apply to a serverless application: 1. Codebase 2. Dependencies 3. Config 4. Backing services 5. Build, release, run 6. Process 7. Port Binding 8. Concurrency 9. Disposability 10. Dev/prod parity 11. Logs 12. Admin processes https://12factor.net
  • 9. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. 1. Codebase 12Factor: “One codebase tracked in revision control, many deploys” Serverless Apps: All code should be stored in revision control (a development best practice). Same repository should be used for all environments deployed to. The bounds of an “application” differ in serverless terms: • If events are shared (i.e., a common Amazon API Gateway) then Lambda function code for those events should be put in the same repository • Otherwise break “services” into their own repositories
  • 10. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. 2. Dependencies 12Factor: “Explicitly declare and isolate dependencies” Serverless Apps: Code that is used by multiple functions should be packaged into its own library. Include those libs inside your deployment package or into a AWS Lambda Layer. Node.js, Python, Ruby • Use npm/pip to install libraries • All dependencies must be at root level • .zip file consisting of your code and any dependencies Java • Either .zip file with all code/dependencies, or standalone .jar • Use Maven / Eclipse IDE plugins • Compiled class & resource files at root level, required jars in /lib directory C# (.NET Core) • Either .zip file with all code / dependencies, or a standalone .dll • Use NuGet / VisualStudio plugins • All assemblies (.dll) at root level Go • .zip file consisting of your Go binary and any dependencies • Use “go get” to install dependencies
  • 11. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Lambda Layers Lets functions easily share code: Upload layer once, reference within any function Layer can be anything: dependencies, training data, configuration files, etc Promote separation of responsibilities, lets developers iterate faster on writing business logic Built in support for secure sharing by ecosystem
  • 12. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. 3. Config 12Factor: “Store config in the environment” Serverless Apps: Many ways to do this in serverless applications: • Lambda environment variables • API Gateway stage variables • AWS Systems Manager Parameter Store
  • 13. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. 4. Backing services 12Factor: “Treat backing services as attached resources” Serverless Apps: No differences. Resources that Lambda functions connect to, such as databases, should have their endpoints and access credentials made available via config resources or IAM policies
  • 14. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. 5. Build, Release, Run 12Factor: “Strictly separate build and run stages” Serverless Apps: No differences. Development best practices such as Continuous Integration and Continuous Delivery should be followed. • Use AWS CodeBuild and AWS CodePipeline to support this: AWS CodeBuild AWS CodePipeline
  • 15. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. CI/CD for serverless applications • Source code repository hosts SAM template • CodePipeline per application • CodeBuild generates a deployable artifact • CodePipeline/CodeDeploy deploys to different environments, with the right config CodeBuildCodeCommit CodePipeline CloudFormation API Gateway Lambda Dev account Step Functions DynamoDBCodeDeploy CloudFormation API Gateway Lambda Test account Step Functions DynamoDB CodeDeploy CloudFormation API Gateway Lambda Prod account Step Functions DynamoDB CodeDeploy Tools accountCode account
  • 16. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. 6. Process 12Factor: “Execute the app as one or more stateless processes” Serverless Apps: This is inherent in how Lambda is designed already: • Lambda Functions should be treated as stateless components • There is no promise of execution environment re-use between function invocations • Data that needs to be kept should be stored in a stateful service such as a database or cache
  • 17. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. 7. Port binding 12Factor: “Export services via port binding” Serverless Apps: In Lambda/serverless applications this factor doesn’t apply the same due to a difference in how Lambda Functions are accessed: • Instead of a “port” Lambda functions are invoked by an event • Lambda functions are invoked in 3 ways: synchronously, asynchronously, and via stream • Instead of having one function support multiple invocation sources, create independent functions
  • 18. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Lambda execution model Synchronous (push) AWS Lambda function /order Asynchronous (event) AWS Lambda function reqs Poll-based changes AWS Lambda service Function Amazon API Gateway Amazon SNS Amazon S3 Amazon DynamoDB Amazon Kinesis
  • 19. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. 8. Concurrency 12Factor: “Scale out via the process model” Serverless Apps: Doesn’t apply. Lambda functions will scale automatically based on load.
  • 20. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. 9. Disposability 12Factor: “Maximize robustness with fast startup and graceful shutdown” Serverless Apps: Shutdown doesn’t apply as Lambda functions and their invocation are tied directly to incoming events. Speed at startup does matter: • Minimize package size to necessities • Do one thing – smaller package size • Reuse – initializing clients/instances outside the handler • Choose the right environment size for optimal operation
  • 21. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. 10. Dev/prod parity 12Factor: “Keep dev, staging, and production as similar as possible” Serverless Apps: This can be made incredibly easy with serverless applications by: • Making use of environment/stage variables or Parameter Store for configuration information, backend resources, etc • Using Serverless Application Models (SAM) to deploy your application • Having a CI/CD process and tooling that supports multiple environments or accounts
  • 22. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. 11. Logs 12Factor: “Treat logs as event streams” Serverless Apps: Logging (as well as Metric collection) are considered a “universal right” in Lambda: • Console output automatically collected and sent to Amazon CloudWatch Logs • Metrics for Lambda and API Gateway for several key stats are automatically collected and sent to CloudWatch • You can easily send more using the CloudWatch SDK
  • 23. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. 12. Admin processes 12Factor: “Run admin/management tasks as one-off processes” Serverless Apps: Doesn’t apply to Lambda since you already limit your functions based on use case. True administrative tasks would occur via their own Lambda Functions.
  • 24. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS Serverless Application Model (SAM) • AWS CloudFormation extension optimized for serverless • Special serverless resource types: • Functions, APIs, SimpleTables and Layers • CLI tool for local development, debugging, testing, deploying, and monitoring of serverless applications https://aws.amazon.com/serverless/sam
  • 25. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  • 26. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Takeaways • The 12 factor app methodology can assist with designing modern applications properly • Many factors are already built into serverless applications • Serverless applications assist with focusing on our core business https://aws.amazon.com/serverless/
  • 27. Thank you! © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Uri Segev Oren Reuveni http://bit.ly/2SFkTzT