Serverless Architectural Patterns - Amazon Web Servicesaws-de-media.s3. 2018/SER3-Serverless...آ  آ©

  • View
    0

  • Download
    0

Embed Size (px)

Text of Serverless Architectural Patterns - Amazon Web Servicesaws-de-media.s3. 2018/SER3-Serverless...آ ...

  • © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

    Serverless Architectural Patterns Pawan Puthran Technical Account Manager

    pputhran@amazon.com @pawanputhran pputhran

  • © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

    Agenda

    • Serverless Foundation • Web application • Data Lake • Stream processing • Operations automation

  • © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

    A serverless world…

    Build and run applications without thinking about servers

    … pay per request not for idle

    “ Scales with usage High availability built-in

    Never pay for idle No servers to provision or manage”

  • © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

    Building blocks for serverless applications

    AWS Lambda Amazon DynamoDB

    Amazon SNS

    Amazon API Gateway Amazon SQS Amazon Kinesis

    Amazon S3

    Orchestration and State Management

    API Proxy and GraphQL Messaging and Queues Analytics

    Monitoring and Debugging

    Compute Storage Database

    AWS X-RayAWS Step Functions Amazon Cognito

    User Management and IdP

    AWS AppSync Amazon Athena

    AWS Lambda@Edge

  • © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

    AWS X-Ray Integration with Serverless

    • Lambda instruments incoming requests for all supported languages

    • Lambda runs the X-Ray daemon on all languages with an SDK

    const AW SXRay = require(‘aws-xray-sdk-core‘);

    AW SXRay.m iddleware.setSam plingRules(‘sam pling-rules.json’);

    const AW S = AW SXRay.captureAW S(require(‘aws-sdk’)); S3Client = AW S.S3();

  • © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

    X-Ray Trace Example

  • © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

    AWS Serverless Application Model (SAM)

    • CloudFormation extension optimized for serverless

    • New serverless resource types: functions, APIs, and tables

    • Supports anything CloudFormation supports

    • Open specification (Apache 2.0) • SAM Translator recently open sourced.

    https://github.com/awslabs/serverless-application-model

  • © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

    SAM CLI

    • Develop and test Lambda locally • Invoke functions with mock

    serverless events • Local template validation • Local API Gateway with hot

    reloading

    https://github.com/awslabs/aws-sam-cli

  • © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

    Delivery via CodePipeline

    Pipeline flow: 1. Commit your code to a source code repository 2. Package/test in CodeBuild 3. Use CloudFormation actions in CodePipeline to create

    or update stacks via SAM templates Optional: Make use of ChangeSets

    4. Make use of specific stage/environment parameter files to pass in Lambda variables

    5. Test our application between stages/environments Optional: Make use of manual approvals

  • © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

    AWS CodeDeploy and Lambda Canary Deployments

    • Direct a portion of traffic to a new version

    • Monitor stability with CloudWatch

    • Initiate rollback if needed • Incorporate into your SAM

    templates

  • © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

    Lambda Best Practices

    • Minimize package size to necessities • Separate the Lambda handler from core logic • Use Environment Variables to modify operational behavior • Self-contain dependencies in your function package • Leverage “Max Memory Used” to right-size your functions • Delete large unused functions (75GB limit)

  • © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

    Pattern 1: Web App/Microservice/API

  • © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

    Web application

    Data stored in Amazon

    DynamoDB

    Dynamic content in AWS Lambda

    Amazon API Gateway

    Browser

    Amazon CloudFront

    Amazon S3

    Amazon Cognito

  • © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

    Bustle Achieves 84% Cost Savings with AWS Lambda

    Bustle is a new s, entertainm ent, lifestyle, and fash ion w ebsite targeted tow ards w om en.

    With AWS Lambda, we eliminate the need to worry

    about operations

    Tyler Love CTO, Bustle

    “ • Bustle had trouble scaling and maintaining high availability for its website without heavy management

    • Moved to serverless architecture using AWS Lambda and Amazon API Gateway

    • Experienced approximately 84% in cost savings

    • Engineers are now focused on innovation

  • © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

    Amazon API Gateway AWS

    Lambda Amazon

    DynamoDB

    Amazon S3

    Amazon CloudFront

    • Bucket Policies • ACLs

    • Origin Access Identity (OAI) • Geo-Restriction • Signed Cookies • Signed URLs • DDOS Protection

    IAM

    AuthZ

    IAM

    Serverless web app security

    • Throttling • Caching • Usage Plans • ACM

    Sta tic

    Con ten

    t

    Browser

    Amazon Cognito

  • © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

    Authorization with Amazon Cognito

    Cognito User Pool (CUP)

    Am azon API G atew ay

    Web Identity Provider

    User A

    User B

    User C

    Cognito Identity Pool (CIP)

    /web

    /cip

    /cup

    AW S Lam bda

    Am azon D ynam oD B

    Token

    AW S Credentials

    User A Data

    User B Data

    Us er

    C Da

    ta

    IAM Authorization

    IAM

    Au tho

    riz ati

    on

    Cognito UP Authorizer

    API Resources

    C C

    A A

    A B

    BB

  • © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

    Custom Authorizer Lambda functionClient

    Lambda function

    Amazon API Gateway

    Amazon DynamoDB

    AWS Identity & Access Management

    SAML Two types: • TOKEN - authorization token

    passed in a header • REQUEST – all headers, query

    strings, paths, stage variables or context variables.

    Custom Authorizers

  • © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

    Multi-Region with API Gateway

    eu-central-2

    eu-west-1

    C lient

    Am azon Route 53

    Regional API

    Endpoint

    Regional API

    Endpoint

    Custom Domain Name

    Custom Domain Name

    API Gateway

    API Gateway

    Lambda

    Lambda

    ap i.m

    yc or

    p. co

    m

    CNAM E

    CN AM

    E

  • © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

    Useful Frameworks for Serverless Web Apps

    • AWS Chalice Python Serverless Framework https://github.com/aws/chalice Familiar decorator-based API similar to Flask/Bottle Similar to third-party frameworks, Zappa or Claudia.js

    • AWS Serverless Express Run Node.js Express apps https://github.com/awslabs/aws-serverless-express

    • Java - HttpServlet, Spring, Spark and Jersey https://github.com/awslabs/aws-serverless-java-container

    https://github.com/aws/chalice https://github.com/awslabs/aws-serverless-express https://github.com/awslabs/aws-serverless-java-container

  • © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

    Pattern 2: Data Lake

  • © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.