Diese Präsentation wurde erfolgreich gemeldet.
Die SlideShare-Präsentation wird heruntergeladen. ×

Getting Started with AWS Lambda and the Serverless Cloud - AWS Summit Cape Town 2017

Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Wird geladen in …3
×

Hier ansehen

1 von 49 Anzeige

Getting Started with AWS Lambda and the Serverless Cloud - AWS Summit Cape Town 2017

Serverless computing allows you to build and run applications without the need for provisioning or managing servers. With serverless computing, you can build web, mobile, and IoT backends; run stream processing or big data workloads; run chatbots, and more. In this session, you’ll learn how to get started with serverless computing with AWS Lambda, which lets you run code without provisioning or managing servers. We’ll introduce you to the basics of building with Lambda and how you can benefit from features such as continuous scaling, built-in high availability, integrations with AWS and third-party apps, and subsecond metering pricing. We’ll also introduce you to the broader portfolio of AWS services that help you build serverless applications with Lambda, including Amazon API Gateway, Amazon DynamoDB, AWS Step Functions, and more.

AWS Speaker : Danilo Poccia, Technical Evangelist - Amazon Web Services

Serverless computing allows you to build and run applications without the need for provisioning or managing servers. With serverless computing, you can build web, mobile, and IoT backends; run stream processing or big data workloads; run chatbots, and more. In this session, you’ll learn how to get started with serverless computing with AWS Lambda, which lets you run code without provisioning or managing servers. We’ll introduce you to the basics of building with Lambda and how you can benefit from features such as continuous scaling, built-in high availability, integrations with AWS and third-party apps, and subsecond metering pricing. We’ll also introduce you to the broader portfolio of AWS services that help you build serverless applications with Lambda, including Amazon API Gateway, Amazon DynamoDB, AWS Step Functions, and more.

AWS Speaker : Danilo Poccia, Technical Evangelist - Amazon Web Services

Anzeige
Anzeige

Weitere Verwandte Inhalte

Diashows für Sie (20)

Ähnlich wie Getting Started with AWS Lambda and the Serverless Cloud - AWS Summit Cape Town 2017 (20)

Anzeige

Weitere von Amazon Web Services (20)

Aktuellste (20)

Anzeige

Getting Started with AWS Lambda and the Serverless Cloud - AWS Summit Cape Town 2017

  1. 1. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Danilo Poccia, Technical Evangelist @danilop Getting Started with AWS Lambda and Serverless Computing
  2. 2. AWS compute offerings VM Task Function Service EC2 ECS Lambda H/W OS Runtime Unit of scale Level of abstraction
  3. 3. AWS compute offerings I want to configure servers, storage, networking, and my OS I want to run servers, configure applications, and control scaling Run my code when it’s needed Service EC2 ECS Lambda How do I choose?
  4. 4. Why AWS Lambda?
  5. 5. Servers How will the application handle server hardware failure? How can I control access from my servers? When should I decide to scale out my servers? When should I decide to scale up my servers? What size servers are right for my budget? How much remaining capacity do my servers have? (AAHHHHHHHHH!!)
  6. 6. Operations and management Scaling Provisioning and utilization Availability and fault tolerance Owning servers means dealing with ...
  7. 7. AWS Lambda: Run code in response to events FUNCTION SERVICES (ANYTHING) Changes in data state Requests to endpoints Changes in resource state Node Python Java C# EVENT SOURCE
  8. 8. No servers to provision or manage Scales with usage Never pay for idle Availability and fault tolerance built in Benefits of Lambda and serverless compute
  9. 9. AWS Lambda Pricing • Buy compute time in 100 ms increments • Low request charge • No hourly, daily, or monthly minimums • No per-device fees Never pay for idle! Free Tier 1 million requests and 400,000 GBs of compute every month, every customer
  10. 10. AWS Lambda Amazon DynamoDB Amazon SNS Amazon API Gateway Amazon SQS Amazon KinesisAmazon S3 Serverless Compute and API Proxy AWS X-Ray AWS Step Functions Services for Building Serverless Applications Database, Storage, State Management, Analytics, Messaging & Queues Developer Tools AWS CodeBuild AWS CodePipelineAWS SAM Third-Party Tools Open Source
  11. 11. Amazon API Gateway: Serverless APIs 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 Amazon API Gateway Any other AWS service
  12. 12. Amazon API Gateway Benefits Create a unified API frontend for multiple microservices DDoS protection and throttling for backend systems Authenticate and authorize requests
  13. 13. “I want to sequence functions” “I want to select functions based on data” “I want to run functions in parallel” “I want to retry functions” “I want to try/catch/finally” “I want to run code for hours” Orchestration for serverless apps AWS Step Functions
  14. 14. AWS Step Functions Easily coordinate multiple Lambda functions using visual workflows Visualize in the Console Define in JSON Monitor Executions https://states-language.net/spec.html
  15. 15. Benefits of Step Functions orchestration Change and add steps without writing code to evolve applications and innovate faster Coordinate and visualize Lambda functions as a series of steps to quickly create serverless apps Automatically trigger and track each step at scale and handle errors with built-in retry and fallback Productivity AgilityResilience
  16. 16. How it works
  17. 17. Using AWS Lambda Bring your own code • Node.js, Java, Python, C# • Bring your own libraries (even native ones) Simple resource model • Select power rating from 128 MB to 1.5 GB • CPU and network allocated proportionately Flexible use • Synchronous or asynchronous • Integrated with other AWS services Flexible authorization • Securely grant access to resources and VPCs • Fine-grained control for invoking your functions
  18. 18. Using AWS Lambda Authoring functions • WYSIWYG editor or upload packaged .zip • Third-party plugins (Eclipse, Visual Studio) Monitoring and logging • Metrics for requests, errors, and throttles • Built-in logs to Amazon CloudWatch Logs Programming model • Use processes, threads, /tmp, sockets normally • AWS SDK built in (Python and Node.js) Stateless • Persist data using external storage • No affinity or access to underlying infrastructure
  19. 19. Amazon S3 Amazon DynamoDB Amazon Kinesis AWS CloudFormation AWS CloudTrail Amazon CloudWatch Amazon Cognito Amazon SNS Amazon SES Cron Events DATA STORES ENDPOINTS CONFIGURATION REPOSITORIES EVENT/MESSAGE SERVICES Example event sources that trigger AWS Lambda … and a few more with more on the way! AWS CodeCommit Amazon API Gateway Amazon Alexa AWS IoT AWS Step Functions Amazon Lex
  20. 20. Use cases
  21. 21. Common use cases Web Applications • Static websites • Complex web apps • Packages for Flask and Express Data Processing • Real time • MapReduce • Batch Chatbots • Powering chatbot logic Backends • Apps & services • Mobile • IoT </></> Amazon Alexa • Powering voice-enabled apps • Alexa Skills Kit IT Automation • Policy engines • Extending AWS services • Infrastructure management
  22. 22. Three-tier web application architecture https://d0.awsstatic.com/whitepapers/AWS_Serverless_Multi-Tier_Architectures.pdf
  23. 23. Here is what that translates to in real life http://media.amazonwebservices.com/architecturecenter/AWS_ac_ra_web_01.pdf
  24. 24. Common use cases Web Applications and Backends Internet Mobile Apps Websites Services AWS Lambda function AWS API Gateway Cache All publicly accessible endpoints Amazon CloudWatch Monitoring Amazon CloudFront Amazon S3 AWS Lambda function AWS Lambda function Amazon DynamoDB Web Applications • Static websites • Complex web apps • Packages for Flask and Express Backends • Apps & services • Mobile • IoT </></>
  25. 25. Task Choice Fail Parallel Lambda + Step Functions Image Recognition and Processing Backend Common use cases Web Applications • Static websites • Complex web apps • Packages for Flask and Express Backends • Apps & services • Mobile • IoT </></>
  26. 26. Serverless IoT with AWS Lambda at iRobot
  27. 27. AWS Lambda Amazon CloudFront Amazon S3 Amazon DynamoDB Amazon Redshift Amazon Route 53 Amazon VPC Amazon CloudWatch AWS CloudFormation AWS CloudTrail AWS Config AWS IAMAWS KMSAWS WAF Amazon Cognito Amazon SNS Amazon API Gateway Amazon SQS Amazon Elasticsearch Service Amazon Kinesis Amazon QuickSight AWS IoT How iRobot leverages AWS
  28. 28. API Gateway App requests over HTTPS CRUD operations
  29. 29. IoT MQTT CRUD operations
  30. 30. IoT MQTT MQTT Presigned URL Staging bucket
  31. 31. Common use cases Web Applications • Static websites • Complex web apps • Packages for Flask and Express Data Processing • Real time • MapReduce • Batch Chatbots • Powering chatbot logic Backends • Apps & services • Mobile • IoT </></> Amazon Alexa • Powering voice-enabled apps • Alexa Skills Kit IT Automation • Policy engines • Extending AWS services • Infrastructure management Lambda + S3
  32. 32. Common use cases Data Processing • Real time • MapReduce • Batch Lambda + Kinesis + DynamoDB
  33. 33. Common use cases Lambda + DynamoDB + Redshift Data Processing • Real time • MapReduce • Batch
  34. 34. Common use cases Web Applications • Static websites • Complex web apps • Packages for Flask and Express Data Processing • Real time • MapReduce • Batch Chatbots • Powering chatbot logic Backends • Apps & services • Mobile • IoT </></> Amazon Alexa • Powering voice-enabled apps • Alexa Skills Kit IT Automation • Policy engines • Extending AWS services • Infrastructure management
  35. 35. Common use cases Web Applications • Static websites • Complex web apps • Packages for Flask and Express Data Processing • Real time • MapReduce • Batch Chatbots • Powering chatbot logic Backends • Apps & services • Mobile • IoT </></> Amazon Alexa • Powering voice-enabled apps • Alexa Skills Kit IT Automation • Policy engines • Extending AWS services • Infrastructure management
  36. 36. • Makers of Dragon Quest • Lambda processes 200-300 images uploaded per minute • Peak processing of 6,000 images per minutes • Reduced image processing time from hours to only 10+ seconds Common use cases
  37. 37. • Business analytics solution for product usage data • Processes 4,000 requests per second • Built the solution in only 2.5 months • Handles spikes in traffic of 2x normal load Common use cases
  38. 38. Best practices
  39. 39. AWS Lambda best practices  Limit your function/code size  Node – remember execution is asynchronous  500 MB /tmp directory provided to each function  Don’t assume function will reuse underlying infrastructure  But take advantage of it when it does occur  You own the logs  Include details from service-provided context  Create custom metrics  Operations-centric vs. business-centric  Use environment variables  Parameterize code and change parameters independent of code updates  Use for securing credentials and keeping them out of code
  40. 40. Best practice: Use versions and aliases Versions = immutable copies of code + properties Aliases = mutable pointers to versions  Rollbacks  Staged promotions  “Lock” behavior for client
  41. 41. AWS CloudFormation brings: • Infrastructure as code • Easy to provision and manage a collection of related AWS resources • Input .yaml file and output provisioned AWS resources • Optimized for infrastructure AWS SAM: • CloudFormation extension optimized for serverless • New serverless resources: functions, APIs, and tables • Supports anything CloudFormation supports • Open specification (Apache 2.0) AWS Serverless Application Model (AWS SAM)
  42. 42. AWSTemplateFormatVersion: '2010 -09-09' Resources: GetHtmlFunctionGetHtmlPermissionProd: Type: AWS::Lambda::Permission Properties: Action: lambda:invokeFunction Principal: apigateway.amazonaws.com FunctionName: Ref: GetHtmlFunction SourceArn: Fn::Sub: arn:aws:execute -api:${AWS::Region}:${AWS::AccountId}:${ServerlessRestApi}/Prod/ANY/* ServerlessRestApiProdStage: Type: AWS::ApiGateway::Stage Properties: DeploymentId: Ref: ServerlessRestApiDeployment RestApiId: Ref: ServerlessRestApi StageName: Prod ListTable: Type: AWS::DynamoDB::Table Properties: ProvisionedThroughput: WriteCapacityUnits: 5 ReadCapacityUnits: 5 AttributeDefinitions: - AttributeName: id AttributeType: S KeySchema: - KeyType: HASH AttributeName: id GetHtmlFunction: Type: AWS::Lambda::Function Properties: Handler: index.gethtml Code: S3Bucket: flourish -demo-bucket S3Key: todo_list.zip Role: Fn::GetAtt: - GetHtmlFunctionRole - Arn Runtime: nodejs4.3 GetHtmlFunctionRole: Type: AWS::IAM::Role Properties: ManagedPolicyArns: - arn:aws:iam::aws:policy/AmazonDynamoDBReadOnlyAccess - arn:aws:iam::aws:policy/service -role/AWSLambdaBasicExecutionRole AssumeRolePolicyDocument: Version: '2012 -10-17' Statement: - Action: - sts:AssumeRole Effect: Allow Principal: Service: - lambda.amazonaws.com ServerlessRestApiDeployment: Type: AWS::ApiGateway::Deployment Properties: RestApiId: Ref: ServerlessRestApi Description: 'RestApi deployment id: 127e3fb91142ab1ddc5f5446adb094442581a90d' StageName: Stage GetHtmlFunctionGetHtmlPermissionTest: Type: AWS::Lambda::Permission Properties: Action: lambda:invokeFunction Principal: apigateway.amazonaws.com FunctionName: Ref: GetHtmlFunction SourceArn: Fn::Sub: arn:aws:execute -api:${AWS::Region}:${AWS::AccountId}:${ServerlessRestApi}/*/ANY/* ServerlessRestApi: Type: AWS::ApiGateway::RestApi Properties: Body: info: version: '1.0' title: Ref: AWS::StackName paths: "/{proxy+}": x-amazon-apigateway-any-method: x-amazon-apigateway-integration: httpMethod: ANY type: aws_proxy uri: Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015 -03- 31/functions/${GetHtmlFunction.Arn}/invocations responses: {} swagger: '2.0' CF template example – API triggering Lambda AWSTemplateFormatVersion: '2010-09-09’ Transform: AWS::Serverless-2016-10-31 Resources: GetHtmlFunction: Type: AWS::Serverless::Function Properties: CodeUri: s3://flourish-demo-bucket/todo_list.zip Handler: index.gethtml Runtime: nodejs4.3 Policies: AmazonDynamoDBReadOnlyAccess Events: GetHtml: Type: Api Properties: Path: /{proxy+} Method: ANY ListTable: Type: AWS::Serverless::SimpleTable AWS SAM example – API triggering Lambda AWS SAM: Less complexity, more power
  43. 43. AWS CodeStar New!
  44. 44. New!AWS X-Ray
  45. 45. The function networking environment  Default - a default network environment within VPC is provided for you  Access to the Internet always permitted to your function  No access to VPC-deployed assets  Customer VPC - Your function executes within the context of your own VPC  Privately communicate with other resources within your VPC  Familiar configuration and behavior with:  Subnets  Elastic network interfaces (ENIs)  EC2 security groups  VPC route tables  NAT gateway
  46. 46. Additional best practices  Externalize authorization to IAM roles whenever possible  Least privilege and separate IAM roles  Externalize configuration  DynamoDB is great for this  Take advantage of Dead Letter Queues  Use to handle failed invocations  Make sure your downstream setup “keeps up” with Lambda scaling  Limit concurrency when talking to relational databases  Analyze and debug your distributed application with AWS X-Ray  Understand how your application and its underlying services are performing
  47. 47. Takeaways • Many applications can go serverless • Data processing, back ends, triggers, web hooks • Lambda functions are opinionated • State, invocation modes, and deployments • The ecosystem continues to grow • Tooling, languages, and application capabilities
  48. 48. Conclusion Lambda is a fundamental component of modern application architectures It has a place in everything from data processing to simple web apps
  49. 49. Thank you! @danilop

×