Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Adopting Reusable Serverless Patterns

Adopting Reusable Serverless Patterns

In this talk, learn more about how the AWS Serverless Application Repository can be used to compose Serverless Applications into larger Serverless architectures to improve agility, quality, and time to market.

Felipe Garcia

April 25, 2019
Tweet

More Decks by Felipe Garcia

Other Decks in Technology

Transcript

  1. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Sam Dengler, Principal Serverless Solutions Architect April 25, 2019 Adopting Reusable Serverless Applications
  2. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Agenda • Serverless Application Model (SAM) • Serverless Application Repository (SAR) • Challenges & Strategies • Demo
  3. © 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
  4. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Lambda is event-driven by nature Services (anything) Changes in data state Requests to endpoints Changes in resource state Event source Function Node.js Python Java C# Go Ruby BYOR (Bring your own runtime)
  5. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. What is a Serverless Application?
  6. © 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, tables, Layers and Applications Supports anything AWS CloudFormation supports Open specification (Apache 2.0) https://aws.amazon.com/serverless/sam NEW!
  7. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. AWS::Serverless::Function AWS::DynamoDB::Table AWS::S3::Bucket SAM Template
  8. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. AWS::Serverless::Function AWS::DynamoDB::Table AWS::S3::Bucket SAM Template
  9. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. SAM Template 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: nodejs6.10 Policies: AmazonDynamoDBReadOnlyAccess Events: GetHtml: Type: Api Properties: Path: /{proxy+} Method: ANY ListTable: Type: AWS::Serverless::SimpleTable
  10. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. SAM Template Tells AWS CloudFormation this is a SAM template it needs to “transform” Creates a AWS Lambda function with the referenced managed AWS IAM policy, runtime, code at the referenced zip location, and handler as defined. Also creates an Amazon API Gateway and takes care of all mapping/permissions necessary Creates a Amazon DynamoDB table 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: nodejs6.10 Policies: AmazonDynamoDBReadOnlyAccess Events: GetHtml: Type: Api Properties: Path: /{proxy+} Method: ANY ListTable: Type: AWS::DynamoDB::Table
  11. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. https://github.com/awslabs/aws-serverless-samfarm/blob/master/api/saml.yaml <-THIS BECOMES THIS-> AWS SAM Templates
  12. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Develop/package/deploy SAM application $ ENV_VAR=VALUE sam local invoke FunctionName --event event.json $ ENV_VAR=VALUE sam local start-api $ sam package --template-file template.yaml \ --s3-bucket my-s3-bucket \ --output-template-file packaged.yaml $ sam deploy --template-file packaged.yaml \ --capabilities CAPABILITY_IAM CAPABILITY_AUTO_EXPAND \ --stack-name my-stack-name \ --parameter-overrides Foo=bar $ sam logs --name FunctionName --stack-name StackName --tail
  13. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Serverless Application Repository (SAR)
  14. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Publishing Applications SAM CLI Publisher Console Publish/Share Apps Publishers (AWS Customers)
  15. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Metadata for SAR AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Parameters: S3BucketParameter: Type: String Outputs: PublicReadAclFunctionArn: Value: !GetAtt PublicReadAclFunction.Arn Metadata: AWS::ServerlessRepo::Application: Name: codepipeline-s3-objects-public-read Description: A Lambda function triggered by CodePipeline to update the S3 ACL to ... Author: Sam Dengler SpdxLicenseId: Apache-2.0 LicenseUrl: LICENSE.txt SemanticVersion: 0.0.1 Resources:
  16. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Publish SAM application to SAR $ sam package --template-file template.yaml \ --s3-bucket my-s3-bucket \ --output-template-file packaged.yaml $ sam publish --template-file packaged.yaml The following metadata of application "arn:aws:serverlessrepo:us-east- 1:068896461592:applications/codepipeline-s3-objects-public-read" has been updated: { "Description": "A Lambda function triggered by CodePipeline to update the S3 ACL ...”, "Author": "Sam Dengler" } Click the link below to view your application in AWS console: https://console.aws.amazon.com/serverlessrepo/home?region=us-east-1#/published- applications/arn:aws:serverlessrepo:us-east-1:068896461592:codepipeline-s3-objects- public-read
  17. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Consuming Applications AWS SDK Public Website Discover & Deploy Apps AWS Lambda Console Consumers (AWS Customers)
  18. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. What is a Nested Application?
  19. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. AWS::Serverless::Function AWS::Serverless::Application AWS::S3::Bucket SAM Template
  20. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. AWS::Serverless::Function AWS::Serverless::Application AWS::S3::Bucket SAM Template AWS::Serverless::Function AWS::DynamoDB::Table Nested App Template
  21. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. AWS::Serverless::Function AWS::Serverless::Application AWS::S3::Bucket SAM Template AWS::Serverless::Function AWS::DynamoDB::Table Nested Stack Root Stack Nested App Template
  22. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. AWS::Serverless::Function AWS::Serverless::Application AWS::S3::Bucket SAM Template
  23. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Include SAR application AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Resources: S3Bucket: Type: AWS::S3::Bucket CodePipelineWebsiteS3ObjectsPublicRead: Type: AWS::Serverless::Application Properties: Location: ApplicationId: arn:aws:serverlessrepo:us-east-1:068896461592:applications/codepip SemanticVersion: 0.0.1 Parameters: S3BucketParameter: !Ref S3Bucket !GetAtt CodePipelineWebsiteS3ObjectsPublicRead.Outputs.PublicReadAclFunctionArn
  24. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Challenges & Strategies
  25. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Shifting Complexity System Code System Code Code Code Code Code Code Code Code Code
  26. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. SQS queue SQS queue DLQ DLQ Redrive DLQ DLQ Redrive DLQ DLQ Redrive Alarm Alarm Alarm Hidden Complexity
  27. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. SQS queue SQS queue DLQ DLQ Redrive DLQ DLQ Redrive DLQ DLQ Redrive Alarm Alarm Alarm Duplication
  28. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. SQS queue SQS queue sqs-dlq app sqs-dlq app lambda-dlq app Duplication
  29. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. SQS queue SQS queue sqs-dlq app sqs-dlq app lambda-dlq app Duplication
  30. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. SQS queue sqs-dlq app lambda-dlq app fork-event-search-analytics-pipeline app Duplication
  31. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. WebSocket API Demo
  32. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. WebSockets support in Amazon API Gateway Real-time two-way communications Managed persistence Event-based triggers Mobile apps Chat Dashboar ds IoT devices Amazon API Gateway WebSockets API Stateful connection Stateless connection AWS Lambda Functions Public Endpoints on Amazon EC2 Amazon Kinesis Any other AWS service All publicly accessible endpoints
  33. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. subscribe $disconnect unsubscribe $connect send Control Plane Data Plane Alice Bob https://abcd10xyz9.execute-api.us-east-1.amazonaws.com/prod/@connections/connectionId
  34. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. subscribe $disconnect unsubscribe $connect send Control Plane Data Plane Alice Bob https://abcd10xyz9.execute-api.us-east-1.amazonaws.com/prod/@connections/connectionId
  35. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. $disconnect subscribe unsubscribe $connect send Alice Bob Control Plane Data Plane CallbackFactory Application https://abcd10xyz9.execute-api.us-east-1.amazonaws.com/prod/@connections/connectionId
  36. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. $disconnect subscribe unsubscribe $connect send Alice Bob Control Plane Data Plane CallbackFactory Application https://abcd10xyz9.execute-api.us-east-1.amazonaws.com/prod/@connections/connectionId
  37. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. $disconnect subscribe unsubscribe $connect send Alice Bob WebSocket Application CallbackFactory Application
  38. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Alice Bob WebSocket Application Checkout Transaction E-Commerce Application
  39. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Thank you! serverlessrepo.aws.amazon.com