Giter Club home page Giter Club logo

codedeployhook's Introduction

Safe AWS Serverless website deployments made easy

The AWS Serverless Application Model (SAM) defines a simplified framework on top of CloudFormation for building serverless apps. It has great support for safe deployments and is well-documented. This safe deployment functionality works for a Lambda in any scenario - not just websites. As such, it's very general-purpose. This flexibility comes at the cost of having to reinvent a pretty common wheel. That's where this app comes in.

How it works

When configured as a PreTraffic "hook" for your AWS::Serverless::Function, the following happens during a sam deploy:

  • New version of Lambda function is published. No traffic is going to it yet. The function's alias is still sending 100% of traffic to the previous version.

  • CloudFormation notifies CodeDeploy that there is a new version of the function ready to start receiving traffic.

  • CodeDeploy invokes the pre-traffic hook (this app) and tells it that it's ready to start the traffic shifting. At this point no traffic has been shifted yet.

  • This app interprets the CodeDeploy hook payload to figure out which version of your function has just been deployed. It then invokes the new function version with a GET /healthcheck request in API Gateway* format.

  • If the new code version return a 2xx-3xx: success! This app notifies CodeDeploy that the new function version is good to be deployed.

  • CodeDeploy now starts shifting traffic to the new version at the rate defined in your DeploymentPreference.Type property.

  • Alternatively, if the new function code did not return a 2xx or 3xx, it is considered non-viable and this app notifies CodeDeploy that it's no good.

  • CodeDeploy marks the deployment as failed, reports back to CloudFormation and the stack is rolled back.

Installation

The app is installable through the Serverless App Repository. It's named codedeployhook and ARN is arn:aws:serverlessrepo:us-east-1:607481581596:applications/codedeployhook.

Usage

You should modify your AWS::Serverless::Function resources to look like this (if they're a website!):

  Function:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.handler
      Runtime: python3.7
      Events:
        Api:
          Type: Api
      # now add the following
      AutoPublishAlias: live
      DeploymentPreference:
        Type: AllAtOnce
        Role: !ImportValue ServerlessDeploymentRoleArn
        Hooks:
          PreTraffic: !ImportValue PreTrafficHook      

Roadmap

  • Right now, the app assumes your serverless template only has a single function with a DeploymentPreference configured. If you have multiple functions in a single template, only the first will be checked. This will change to check all configured functions concurrently.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.