Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

Building Serverless Backends with AWS Lambda and Amazon API Gateway

2.204 visualizaciones

Publicado el

AWS Lambda is a compute service that runs your code without provisioning or managing servers. Amazon API Gateway is a fully managed service that makes it easy for developers to publish, maintain, monitor, and secure APIs at any scale.

This session will familiarize you with the basics of AWS Lambda and Amazon API Gateway and demonstrate how to build web, mobile, and IoT backends using these services. You will learn how to setup API endpoints that trigger AWS Lambda functions to handle mobile, web, IoT, and 3rd party API requests. You will also learn how to use Lambda to read and write to Amazon DynamoDB. We will run through a demo of setting up a simple serverless blogging web application that allows user authentication and the ability to create posts and comments.

Publicado en: Tecnología
  • Sé el primero en comentar

Building Serverless Backends with AWS Lambda and Amazon API Gateway

  1. 1. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Stefano Buliani, Specialist solutions architect, Serverless October 24, 2016 Building Serverless Backends Using AWS Lambda and Amazon API Gateway
  2. 2. Agenda • Why serverless backends • Introduction to AWS Lambda • Introduction to Amazon API Gateway • Demo: Hello world API • Demo: Running Express apps in AWS Lambda • Best practices
  3. 3. Everybody knows this 3-tier web app diagram Presentation Tier Logic Tier Data Tier Mobile App Web Server Database
  4. 4. Here is what that translates to in real life http://media.amazonwebservices.com/architecturecenter/AWS_ac_ra_web_01.pdf
  5. 5. The server-less stack InternetMobile apps AWS Lambda functions AWS API Gateway Other AWS services
  6. 6. Managed The server-less stack – zoom in InternetMobile apps AWS Lambda functions AWS API Gateway cache Endpoints on Amazon EC2 Any other publicly accessible endpoint Amazon CloudWatch Amazon CloudFront API Gateway API Gateway Other AWS services AWS Lambda functions
  7. 7. Abstraction in AWS Compute offerings VM App Function Service EC2 ECS Lambda H/W OS Runtime Unit of scale Level of abstraction
  8. 8. Cost-effective and efficient No Infrastructure to manage Pay only for what you use Bring Your Own Code Productivity focused compute platform to build powerful, dynamic, modular applications in the cloud Run code in standard languages Focus on business logic Benefits of AWS Lambda 1 2 3
  9. 9. Applications Components for Serverless apps EVENT SOURCE FUNCTION SERVICES (ANYTHING) Changes in data state Requests to endpoints Changes in resource state Node Python Java … more coming soon
  10. 10. Amazon S3 Amazon DynamoDB Amazon Kinesis AWS CloudFormation AWS CloudTrail Amazon CloudWatch Amazon SNS Amazon SES Amazon API Gateway Amazon Cognito AWS IoT Amazon Alexa Cron events DATA STORES ENDPOINTS REPOSITORIES EVENT/MESSAGE SERVICES Event Sources that integrate with AWS Lambda … and the list will continue to grow! Amazon RDS Aurora
  11. 11. Benefits of Amazon API Gateway Create a unified API frontend for multiple micro- services Authenticate and authorize requests to a backend DDoS protection and throttling for your backend Throttle, meter, and monetize API usage by 3rd party developers
  12. 12. API Gateway integrations Internet Mobile Apps Websites Services AWS Lambda functions AWS API Gateway Cache Endpoints on Amazon EC2 All publicly accessible endpoints Amazon CloudWatch Monitoring Amazon CloudFront Any other AWS service
  13. 13. Customer use case: API-first migration to the cloud
  14. 14. 1. Use API Gateway to front existing backends InternetClient API Gateway Hosted service 1 Hosted service 2 AWS cloud corporate data center
  15. 15. 2. Lift & shift service to AWS InternetClient API Gateway Hosted service 1 Service 2 on EC2 AWS cloud corporate data center
  16. 16. 3. Lift & re-architect InternetClient API Gateway Service 2 on EC2 AWS cloud Microservice 1 Microservice 2 Microservice 3 Re-architected Service 1
  17. 17. Demo: Hello World API
  18. 18. Using API Gateway Input/Output Transforms Filter output results • Remove private/unnecessary data • Filter dataset size to improve API performance Translate between client-backend • Convert GET query string parameters to body for POST • Talk XML to API user-interface but JSON to Lambda
  19. 19. 3 new features in API Gateway • Catch-all resource paths • ANY http method • PROXY integrations Root/ /store/{path+} * (ANY) OPTIONS /catalogue/{path+} * (ANY) Store Lambda Function Mock integration for CORS support HTTP service on EC2 Automatic request mapping { resource: “/store/{path+}”, path: “/store/items/1423”, httpVerb: “GET”, headers: { “Content-Type”: “application/json”, “x-custom-header” : “1” }, queryStringParameters: { }, pathParameters: { petId: “1” }, requestContext: { }, stageVariables: { } body : “” } Default response structure { statusCode: int, body: string, headers: { "Content-Type": "application/json", "x-Custom-Header" : “1" } }; Full request/response passthrough
  20. 20. Demo: Running an Node.js Express app in AWS Lambda
  21. 21. Best practices
  22. 22. Attaching Lambda functions to RESTful HTTP Endpoints • 1:1 Mapping: Every API call triggers a stateless Lambda function • Add caching to API calls to return a cached response instead for duplicate requests • API Gateway concepts: An API is defined as a set of resources and methods • Resource: A logical entity that can be accessed within an API • Method: The combination of a resource path and an HTTP verb such as GET/POST • Automatic Scaling: Both API Gateway and Lambda scale automatically with calls • Safety throttle of 100 concurrent Lambda functions, can be increased by AWS Support Center • User defined standard-rate limit and a burst-rate limit per second for each API method
  23. 23. Best practices for creating Lambda functions • Memory: CPU proportional to the memory configured • Increasing memory makes your code execute faster (if CPU bound) • Timeout: Increasing timeout allows for longer functions, but more wait in case of errors • Retries: For API Gateway, Lambda doesn’t retry the function execution, but the Gateway generated SDKs retry throttled requests • Permission model: API Gateway synchronously triggers Lambda, so assign API Gateway a resource policy to invoke Lambda.
  24. 24. What are stage variables • Stage variables act like environment variables • Use stage variables to store configuration values • Stage variables are available in the $context object • Values are accessible from most fields in API Gateway • Lambda function ARN • HTTP endpoint • Custom authorizer function name • Parameter mappings
  25. 25. Stage variables and Lambda alias for stages Using Stage Variables in API Gateway together with Lambda function Aliases helps you manage a single API configuration and Lambda function for multiple stages myLambdaFunction 1 2 3 = prod 4 5 6 = beta 7 8 = dev My First API Stage variable = lambdaAlias Prod lambdaAlias = prod Beta lambdaAlias = beta Dev lambdaAlias = dev
  26. 26. Manage Multiple Versions and Stages of your APIs Works like a source repository – clone your API to create a new version API 1 (v1) Stage (dev) Stage (prod) API 2 (v2) Stage (dev)
  27. 27. Custom Domain Names Use custom domain names to put 2 APIs under the same domain • Custom domain names can point to an API or a Stage • A custom domain name can include a base path • Use v1 as your base path in the custom domain name • Pointing to an API you have access to all Stages • Beta (e.g. yourapi.com/v1/beta) • Prod (e.g. yourapi.com/v1/prod) • Pointing directly to your “prod” Stage • Prod (e.g. yourapi.com/v1)
  28. 28. Three Next Steps 1. Check out http://squirrelbin.com/ 2. Try out the “Serverless Web-App Reference Architecture” at https://github.com/awslabs/lambda-refarch-webapp/ 3. Check out some serverless frameworks: 1. https://github.com/awslabs/chalice (Python) 2. https://github.com/awslabs/aws-serverless-express (Express) 3. https://serverless.com/ (Serverless framework)
  29. 29. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved. All attendees will receive a special giveaway gift! Please join us for the AWS DevDay Networking Reception 5:00 - 6:30 PM JW Grand Foyer
  30. 30. Thank You! @sapessi

×