Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

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

675 views

Published on

The Twelve-Factor App Methodology introduces best practices for building modern, cloud-native applications. In this session you'll learn how to directly apply the Twelve-Factor methodology to modern application development with Lambda and Amazon API Gateway. As you'll see, many of these factors are not only directly applicable to serverless applications and can be applied to various architectures and solutions.

  • Be the first to comment

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

  1. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 25. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  26. 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. 27. Thank you! © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Uri Segev Oren Reuveni http://bit.ly/2SFkTzT

×