npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

serverless-gradual-traffic-shifting

v0.1.1

Published

A Serverless plugin to implement gradual deployment of Lambda functions

Downloads

976

Readme

npm version

Serverless Gradual Traffic Shifting for Lambda

A Serverless plugin to implement gradual traffic shifting of Lambda functions, using lambda traffic shifting feature

This project takes inspiration from the plugin Serverless Canary Plugin by David García.

Why do we need this?

Presently CodeDeploy Canary and Linear deployments are very restrictive in nature and allow only single interval deployment setting as default presets. Even if we create a custom deployment config we can only specify Linear/Canary with single interval and it needs the CodeDeploy application to be running. AWS Lambda provides the Traffic Shifting api's which can be leveraged to route desired traffic to any version of lambda without worrying about the CodeDeploy application restrictions.

(As per AWS the multiple interval there are features requests to respect multiple intervals and traffic percentages)

This type of traffic shifting may not be required by many projects in which 100% traffic is routed within a couple of hours and the existing Canary/Linear Configuration works fine in those cases. However, if we need a custom solution in which on day 1 say only 5% of traffic is allowed and the analytics and usage need to be stufied for a longer duration, then this feature will be helpful.

Furthermore, a custom Lambda can be created to route the remaining traffic after running analytics on the api's which update the alias with new traffic info

Installation

npm i --save-dev serverless-gradual-traffic-shifting

Usage

To enable gradual deployments for Lambda functions, the serverless.yml should be configured like this:

service: gradual-traffic-shifting
provider:
  name: aws
  runtime: nodejs6.10
  
plugins:
  - serverless-gradual-traffic-shifting

functions:
  hello:
    handler: handler.hello
    events:
      - http: GET hello
    deploymentSettings:
      alias: Live
      versionWeight: 0.20
      liveVersion: 2

Check out the working example in the example folder.

Configuration

  • alias: (required) name that will be used to create the Lambda function alias.

  • versionWeight: (optional) defines the weight of the traffic to be shifted to the new version after sls deploy, if not present shifts 100% traffic to newwer version.

  • liveVersion: (optional, but required if versionWeight is specified) defines the required version which will get the remaining traffic from the versionWeight. E.g:

Traffic configurations

If deploymentSettings section is defined with settings

functons:
  helloWorldFunction:
    handler: index.handler
    deploymentSettings:
        alias: Live
        versionWeight: 0.60 #any number from 0.00 - 1 (0 - 100 %)
        liveVersion: 2 #provived version 2 is already present
resources:
  ...

In this case 60% Traffic will be routed to new version (3 after deployment) and remaining 40% wil be routed to version 2 as specifed in config.

How it works

The plugin is based on the AWS Lambda traffic shifting feature to balance traffic between versions. It takes the versionWeight and version info in params to create the route config for lambda alias It updates the CloudFormation template generated by Serverless, so that:

  1. It creates a Lambda function Alias for each function with RoutingConfig and AdditionalVersionWeights getting the function version and function weight from the deployment settings
  2. It modifies events that trigger Lambda functions, so that they invoke the newly created alias.

Note

AWS CloudFormation creates a new version for Lambda only when there is change in the function code, so if there is no code change then specifying liveVersion setting with function version number will result in an error.

  Function version already specified in Routing Config

Please ensure the serverless.yml file has the versionFunctions flag set to true.

provider:
  versionFunctions: true

Limitations

The plugin works with Lambda functions invoked by API Gateway, Streams, Sns, S3 and needs the additional function version to be specfied. It can be further enhanced (if required) to get the existing version if present and route the remaining traffic to it.

License

ISC © Pritam Paul