Save 37% off PRO during our Black Friday Sale! »

How to Build and Deploy Serverless Apps [AWS Summit Cape Town]

How to Build and Deploy Serverless Apps [AWS Summit Cape Town]

Serverless computing allows you to build and run applications without the need for provisioning or managing servers. It means that you can build web, mobile, and IoT backends, run stream processing or big data workloads, build chatbots, run code at the edge, and more.

In this session, learn how to get started with serverless computing with AWS Lambda and managed services such as Amazon API Gateway, Amazon Kinesis, and Amazon DynamoDB. We introduce you to the basics of building with AWS Lambda, as well as how to properly perform CI/CD for your serverless application.

We will discuss a method for automating the deployment of serverless applications using services such as AWS CodePipeline and AWS CodeBuild, and techniques such as canary deployments and automatic rollbacks.

36ca8ae7e19067021d0e39c0b72acc2a?s=128

Alex Casalboni

July 12, 2018
Tweet

Transcript

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

    rights reserved. Alex Casalboni Technical Evangelist, AWS How to Build and Deploy Serverless Apps @alex_casalboni
  2. About me • Software Engineer & Web Developer • Serverless

    Lover & AI Enthusiast • AWS Customer since 2013
  3. Agenda 1. What is serverless computing 2. Serverless patterns on

    AWS 3. What customers are building 4. Safe deployments for AWS Lambda 5. Demo time bit.ly/cape-town-serverless
  4. What is serverless computing

  5. Serverless Computing in a nutshell No servers to provision or

    manage Scales with usage Never pay for idle Built-in availability and fault tolerance
  6. Event-driven architectures Services (anything) Changes in data state Requests to

    endpoints Changes in resource state Event source Lambda function Node.js Python Java C# Go
  7. Common Use Cases Web apps • Static websites • Complex

    web apps • Packages for Flask and Express Data processing • Real time • MapReduce • Batch • Machine learning inference Chatbots • Powering chatbot logic Backends • Apps and services • Mobile • IoT </> </> Amazon Alexa • Powering voice-enabled apps • Alexa Skills Kit IT automation • Policy engines • Extending AWS services • Infrastructure management
  8. 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 … and more on the way. AWS CodeCommit Amazon API Gateway Amazon Alexa AWS IoT AWS Step Functions Amazon SQS New
  9. Serverless patterns on AWS

  10. Using AWS Lambda Simple resource model • Select power rating

    from 128 MB to 3 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 Bring your own code • Node.js, Java, Python, C#, Go • Bring your own libraries (even native ones)
  11. Using AWS Lambda Authoring functions • WYSIWYG editor or upload

    packaged .zip • AWS Cloud9 IDE • Third-party plugins (Eclipse, Visual Studio) Monitoring and logging • Metrics for requests, errors, and throttles • Built-in logs to Amazon CloudWatch Logs • Distributed tracing with AWS X-Ray 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
  12. AWS Lambda Execution Model Synchronous (push) Asynchronous (event) Stream-based Amazon

    API Gateway AWS Lambda function Amazon DynamoDB Amazon SNS AWS Lambda function Amazon S3 reqs changes AWS Lambda service function /order Amazon Kinesis
  13. Amazon API Gateway Unified API frontend Authenticate and authorize requests

    DDoS protection and throttling Throttle, meter, and monetize APIs
  14. Mobile Apps Websites Services Amazon API Gateway API Gateway Cache

    Public Endpoints on Amazon EC2 Amazon CloudWatch Monitoring All publicly accessible endpoints Lambda Functions Endpoints in VPC Applications & Services in VPC Any other AWS service Fully-managed CloudFront Distribution Edge-Optimized Regional Private Customer-managed CloudFront Distribution Applications & Services in the same AWS Region AWS Direct Connect On-premises Amazon API Gateway Integrations
  15. AWS Lambda@Edge Write Node.js code, upload it to Lambda, and

    run it on 119 edge locations Run code at an AWS location close to your end user with CloudFront’s global network Leverage computation at the edge and CloudFront’s caching functionalities to reduce origin load Programing model Reduce Origin Load Global network New
  16. AWS Lambda@Edge Triggers

  17. What customers are building

  18. Who’s using AWS Lambda?

  19. Safe deployments for AWS Lambda

  20. AWS Serverless Application Model (SAM) Simplified template driven deployment model

    for serverless applications Supported serverless resource types: functions, APIs, and tables Supports anything AWS CloudFormation supports Open specification (Apache 2.0) github.com/awslabs/serverless-application-model
  21. SAM Template Tells AWS CloudFormation this is a SAM template

    it needs to transform 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 and permissions necessary Creates a DynamoDB table with five read & write units 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
  22. SAM Template Properties Handler: index.js Runtime: nodejs4.3 CodeUri: 's3://my-bucket/my-function.zip' Description:

    Creates thumbnails MemorySize: 1024 Timeout: 15 Policies: AmazonS3FullAccess Environment: Variables: TABLE_NAME: my-table Events: PhotoUpload: Type: S3 Properties: Bucket: my-photo-bucket Tracing: Active|PassThrough From SAM version 2016-10-31 AWS::Serverless::Function AWS::Serverless::Api AWS::Serverless::SimpleTable
  23. SAM Template Properties StageName: prod DefinitionUri: swagger.yml CacheClusterEnabled: true CacheClusterSize:

    28.4 Variables: VarName: VarValue From SAM version 2016-10-31 AWS::Serverless::Function AWS::Serverless::Api AWS::Serverless::SimpleTable
  24. SAM Template Properties PrimaryKey: Name: id Type: String ProvisionedThroughput: ReadCapacityUnits:

    5 WriteCapacityUnits: 5 From SAM version 2016-10-31 AWS::Serverless::Function AWS::Serverless::Api AWS::Serverless::SimpleTable
  25. github.com/awslabs/aws-sam-local AWS SAM Local AWS CLI tool for local testing

    of serverless apps Works with Lambda functions and “proxy-style” APIs Response object and function logs available on your local machine Uses open-source Docker-Lambda images to mimic Lambda’s execution environment (timeout, memory limits, runtimes)
  26. Understanding “CI/CD” Source Build Test Production Continuous integration Continuous delivery

    Continuous deployment
  27. Understanding “CI/CD” for AWS Lambda Source Build Test Production AWS

    CodeCommit AWS CodeDeploy AWS CodeBuild Third-party tooling AWS CodePipeline New
  28. AWS CodeDeploy + Lambda Deployment Preference Type Canary10Percent30Minutes Canary10Percent5Minutes Canary10Percent10Minutes

    Canary10Percent15Minutes Linear10PercentEvery10Minutes Linear10PercentEvery1Minute Linear10PercentEvery2Minutes Linear10PercentEvery3Minutes AllAtOnce • Lambda Alias Traffic Shifting enables canaries and blue|green deployments • Automatic rollback based on CloudWatch Metrics/Alarms • Pre/Post-Traffic Triggers can integrate with other services (or even call Lambda functions)
  29. <demo time>

  30. bit.ly/aws-sam-rollback-demo

  31. © 2018, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Alex Casalboni Technical Evangelist, AWS Thank you! @alex_casalboni