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.

Serverless for Developers

36 views

Published on

Serverless architectures allow you to build and run applications and services without needing to provision, manage, and scale infrastructure. You will learn how to build serverless architectures on AWS using AWS Lambda and integrate with Amazon API Gateway to create a range of applications from data processing systems to mobile backends to web applications. Level : 200 - coding experience required.

Published in: Internet
  • Be the first to comment

  • Be the first to like this

Serverless for Developers

  1. 1. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Serverless Developer Experience Sébastien Stormacq, Developer Evangelist @sebsto
  2. 2. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  3. 3. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. A typical day in developer life
  4. 4. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. We need an app to let our customers update preference settings – our competitors just launched the same thing, so I need it fast. I don’t want to pay a lot for it, especially when no one is using it. But remember that we’re growing, so make sure it scales great and is easy to manage and operate. And you’re on your own – sorry! A typical day in developer life
  5. 5. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. We need an app to let our customers update preference settings – our competitors just launched the same thing, so I need it fast. I don’t want to pay a lot for it, especially when no one is using it. But remember that we’re growing, so make sure it scales great and is easy to manage and operate. And you’re on your own – sorry! A typical day in developer life Not a problem, I’ll make it serverless
  6. 6. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Serverless means
  7. 7. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Serverless means No Server to Provision or Manage Scale with Usage Availability and Fault Tolerance Built-in No Idle Capacity to Pay for
  8. 8. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Serverless across the stack Database AccessCompute Developer Workflow
  9. 9. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS Lambda Changes in data state Requests to endpoints Changes in resource state Event Source Functions Node.js Python Java C# Go Ruby (*)
  10. 10. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Typical 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
  11. 11. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  12. 12. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Fannie Mae Serverless Financial Modeling Financial Modeling is a Monte-Carlo simulation process to project future cash flows, which is used for managing the mortgage risk on daily basis: • Underwriting and valuation • Risk management • Financial reporting • Loss mitigation and loan removal • ~10 Quadrillion (10#10$%) of cash flow projections each month in hundreds of economic scenarios. • One simulation run of ~ 20 million mortgages takes 1.4 hours, >4 times faster than the existing process. The Federal National Mortgage Association
  13. 13. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Hello AWS Lambda World KEEP CALM and WATCH the DEMO
  14. 14. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. How do you … Provision & Configure your Infrastructure ? Manage multiple environments ? Validate your Architecture and Test your application ? Automate all the above ?
  15. 15. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS CloudFormation • Create templates of your infrastructure • CloudFormation provisions AWS resources based on dependency needs • Version control/replicate/update templates like code • Integrates with development, CI/CD, management tools • JSON and YAML supported
  16. 16. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Cloud Formation Template 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'
  17. 17. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Cloud Formation Template 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'
  18. 18. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Meet SAM !
  19. 19. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Serverless Application Model • CloudFormation extension optimized for serverless • Serverless resource types: functions, APIs, tables • Supports anything CloudFormation supports • Open specification (Apache 2.0) https://github.com/awslabs/serverless-application-model
  20. 20. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Cloud Formation Template 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'
  21. 21. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Serverless Application Model (SAM) Creates a Lambda function with the referenced managed IAM policy, runtime, code at the referenced zip location, and handler as defined. Also creates an API Gateway and takes care of all mapping/permissions necessary Tells CloudFormation this is a template to transform AWSTemplateFormatVersion: '2010-09-09’ Transform: AWS::Serverless-2016-10-31 Resources: GetHtmlFunction: Type: AWS::Serverless::Function Properties: CodeUri: s3://sam-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 Creates a DynamodDB table
  22. 22. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Package and Deploy sam package --s3-bucket <BUCKET> --template-file template.yaml --output-template-file packaged.yaml sam deploy --template-file packaged.yaml --stack-name <STACK> --capabilities CAPABILITY_IAM
  23. 23. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. How do you … Provision & Configure your Infrastructure ? Manage multiple environments ? Validate your Architecture and Test your application ? Automate all the above ?
  24. 24. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Configure Multiple Environments
  25. 25. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Configure Multiple Environments Dev SAM Template Test Prod Your choice of Source Code Control
  26. 26. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. How do you … Provision & Configure your Infrastructure ? Manage multiple environments ? Validate your Architecture and Test your application ? Automate all the above ?
  27. 27. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Testing Serverless Apps • Test in an environment that resembles Lambda: • OS • Libraries • Runtime • Configured limits (memory, timeout) • Mimic response and log outputs
  28. 28. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Testing serverless apps - challenges • Test events need to be: • Syntactically accurate • Different for each trigger
  29. 29. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Testing serverless apps - challenges { "Records": [ { "eventVersion": "2.0", "eventTime": "1970-01-01T00:00:00.000Z", "requestParameters": { "sourceIPAddress": "127.0.0.1" }, "s3": { "configurationId": "testConfigRule", "object": { "eTag": "0123456789abcdef0123456789abcdef", "sequencer": "0A1B2C3D4E5F678901", "key": "myKey", "size": 1024 }, "bucket": { "arn": "arn:aws:s3:::myBucket", "name": "myBucket", "ownerIdentity": { "principalId": "EXAMPLE" } }, "s3SchemaVersion": "1.0" }, "responseElements": { "x-amz-id-2": "EXAMPLE123/5678abcdefghijklambdaisawesome/mnopq rstuvwxyzABCDEFGH", "x-amz-request-id": "EXAMPLE123456789" }, "awsRegion": "us-east-1", "eventName": "ObjectCreated:Put", "userIdentity": { "principalId": "EXAMPLE" }, "eventSource": "aws:s3” } ] }
  30. 30. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Introducing the SAM CLI Usage: sam [OPTIONS] COMMAND [ARGS]... … Commands: validate Validate an AWS SAM template. init Initialize a serverless application with a... package Package an AWS SAM application. This is an alias for 'aws cloudformation package'. deploy Deploy an AWS SAM application. This is an alias for 'aws cloudformation deploy'. logs Fetch logs for a function local Run your Serverless application locally for...
  31. 31. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Introducing the SAM CLI https://github.com/awslabs/aws-sam-cli pip install --user aws-sam-cli
  32. 32. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Hello AWS SAM CLI KEEP CALM and WATCH the DEMO
  33. 33. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. How do you … Provision & Configure your Infrastructure ? Manage multiple environments ? Validate your Architecture and Test your application ? Automate all the above ?
  34. 34. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Automate Developer Workflow AWS CodeBuild AWS CodeCommit AWS Cloud9 AWS CodeDeploy AWS CodePipeline Develop Build & Test Deploy
  35. 35. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. buildspec.yaml version: 0.1 environment_variables: plaintext: "INPUT_FILE": "saml.yaml” "S3_BUCKET": ”my_bucket" phases: install: commands: - npm install pre_build: commands: - eslint *.js build: commands: - npm test post_build: commands: - sam package --template $INPUT_FILE --s3-bucket $S3_BUCKET --output-template post-saml.yaml artifacts: type: zip files: - post-saml.yaml - beta.json Variables Different phases of the build Create artifacts and store on them S3
  36. 36. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Safe Deployment with SAM • SAM integrates with Code Deploy • Code Deploy integrates with Lambda • Lambda Versioning supports traffic shifting
  37. 37. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Safe Deployment with SAM • Version = immutable deployment unit • Alias = pointer to a version Lambda Function alias : LIVE version : 6 version : 7 90% 10%
  38. 38. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Safe Deployment with SAM • Preconfigured canary and linear deployments • Auto alarm-based rollbacks • Pre and post traffic validation hooks • Monitor through the CodeDeploy console • Natively supported in SAM!
  39. 39. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Safe Deployment with SAM AWSTemplateFormatVersion: '2010-09-09’ Transform: AWS::Serverless-2016-10-31 Resources: GetHtmlFunction: Type: AWS::Serverless::Function Properties: CodeUri: s3://demo-bucket/todo_list.zip Handler: index.js Runtime: nodejs6.1
  40. 40. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWSTemplateFormatVersion: '2010-09-09’ Transform: AWS::Serverless-2016-10-31 Globals: Function: AutoPublishAlias: Live DeploymentPreference: Type: Canary10Percent10Minutes Resources: GetHtmlFunction: Type: AWS::Serverless::Function Properties: CodeUri: s3://demo-bucket/todo_list.zip Handler: index.js Runtime: nodejs6.1 Policies: AmazonDynamoDBReadOnlyAccess Safe Deployment with SAM
  41. 41. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWSTemplateFormatVersion: '2010-09-09’ Transform: AWS::Serverless-2016-10-31 Globals: Function: AutoPublishAlias: Live DeploymentPreference: Type: Canary10Percent10Minutes Hooks: PreTraffic: !Ref CodeDeployHook_PreTest PostTraffic: !Ref CodeDeployHook_PostTest Alarms: - !Ref DurationAlarm - !Ref ErrorAlarm Resources: GetHtmlFunction: Type: AWS::Serverless::Function Properties: CodeUri: s3://demo-bucket/todo_list.zip Handler: index.js Runtime: nodejs6.1 Safe Deployment with SAM
  42. 42. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Code Deploy Console
  43. 43. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Safe Deployments KEEP CALM and WATCH the DEMO
  44. 44. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Orchestrate Develop Build & Test Deploy
  45. 45. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS CodePipeline • Continuous delivery service for fast and reliable application updates • Model and visualize your software release process • Builds, tests, and deploys your code every time there is a code change • Integrates with third-party tools and AWS
  46. 46. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  47. 47. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. How do you … Provision & Configure your Infrastructure ? Manage multiple environments ? Validate your Architecture and Test your application ? Automate all the above ?
  48. 48. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Access
  49. 49. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Database
  50. 50. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Serverless on AWS Database AccessCompute Developer Workflow
  51. 51. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Take Away 1. Use the Lambda console for quick creation and iteration of simple apps 2. Use AWS SAM to describe your serverless architecture 3. Plug SAM CLI into the IDE of your choice for testing and debugging 4. "Develop in the cloud" with AWS Cloud9 – optimized for serverless applications 5. Build on SAM for CI/CD capabilities, including linear & canary deployments 6. Automate your deployment workflow using Code* family of services
  52. 52. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Thank you Sébastien Stormacq, Developer Evangelist @sebsto

×