aws-blue-green-toolkit
Utility functions to help with performing blue/green and canary deployments in AWS infrastructure
Last updated 12 days ago by bbeesley .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install aws-blue-green-toolkit 
SYNC missed versions from official npm registry.

CircleCI codecov Commitizen friendly semantic-release

aws-blue-green-toolkit

Utility functions to help with performing blue/green and canary deployments in AWS infrastructure

background

AWS support for blue/green and canary deployments is provided by CodeDeploy. CodeDeploy is great in what it does, but it only really manages swapping versions for web services. Any services that sit behind the public facing API don't get managed by the CodeDeploy flow.

A common pattern for blue/green and canary deployments is to not just use a pair of services for the web component, but use a pair of services for the whole pipeline, eg data ingestion, databases, queues, data manipulation lambdas etc. You can manage starting, hydrating, and using these services as part of the CodeDeploy pipeline through the use of hooks (in the form of lambdas). Using these hook lambdas you can manage blue/green or canary deployments of a whole stack of services using the aws-sdk, unfortunately this normally means writing a lot of code to manage the process.

This module is a set of utility functions that I use to reduce the boilerplate required to set up these deploment hook lambdas.

example architecture

For an example web api, using a node application in docker, with a SQL data store, and data updates being published on an SNS topic, the architecture may looks something like this:

In order to manage blue/green deployments for this service, CodeDeploy will directly handle deploying the new ECS service, attaching target groups to load balancers, flipping traffic over to the new service, and tearing down the old containers.

Unfortunately this really only covers less than half of the architecture. Everything from the data updates topic through to the database is up to you to manage through hooks. When deploying a new version of the service, the steps required will be something like this:

  1. Replacement database cluster is started or created
  2. Autoscaling minimum capacity on the new db cluster is set to match the current capacity of the active cluster
  3. Replacement database is purged and the latest schema is created
  4. SNS subscriptions are enabled for the replacement queue
  5. SQS subscription lambda is enabled for the replacement stack
  6. A new task set is created in the ECS service, it is bound to the replacement stack's database
  7. The new task set is placed in a testing target group, this is attached to a testing port on the load balancer
  8. Automated tests are carried out against the replacement service via the testing port
  9. The replacement stack becomes the active stack, what was the active stack is now the old stack.
  10. Autoscaling minimum capacity on the active set is reverted to the normal value, database will scale in when traffic is lower.
  11. SNS subscriptions are disabled for the old stack
  12. SQS subscription for the old stack's ingest queue is disabled
  13. Old database cluster is stopped or deleted
  14. The old SQS queues are purged
  15. The old ECS taskset is destroyed

CodeDeploy will carry out steps 6, 7, 9, and 15. This module contains tools to help you perform the other steps from your deployment hook lambda functions.

api

Table of Contents

AuroraConfig

src/main/AuroraTools.ts:13-18

Extends AwsConfig

Configuration options for the Aurora toolkit

AuroraTools

src/main/AuroraTools.ts:25-258

Toolkit for Aurora operations

getClusterState

src/main/AuroraTools.ts:63-80

Gets the current state of one of the Aurora clusters

Parameters

Returns Promise<ClusterState>

scaleIn

src/main/AuroraTools.ts:118-120

Reverts a cluster's minimum reader count to the configured minimum

Parameters

Returns Promise<void>

scaleOut

src/main/AuroraTools.ts:128-133

Scales out a cluster to match it's partner's size

Parameters

Returns Promise<void>

getReaderCount

src/main/AuroraTools.ts:141-155

Get a count of the number of active readers for a cluster

Parameters

Returns Promise<number> The number of active readers

startDatabase

src/main/AuroraTools.ts:163-166

Starts a stopped db cluster

Parameters

Returns Promise<void>

stopDatabase

src/main/AuroraTools.ts:174-177

Stops a running db cluster

Parameters

Returns Promise<void>

deleteDatabase

src/main/AuroraTools.ts:185-217

Deletes a running db cluster

Parameters

Returns Promise<void>

applyTags

src/main/AuroraTools.ts:226-257

Parses a message from an rds event subscription, if the event was triggered by a scale out operation, the tags defined in config are applied to the newly created reader.

Parameters
  • record SNSEventRecord An SNS event record of the type published by rds event streams

Returns Promise<void>

CloudWatchConfig

src/main/CloudwatchTools.ts:11-14

Extends AwsConfig

Configuration options for the CloudWatch toolkit

CloudWatchTools

src/main/CloudwatchTools.ts:26-78

Toolkit for CloudWatch operations

disableAlarmsActions

src/main/CloudwatchTools.ts:64-67

Disable all alarm actions

Parameters

Returns Promise<void>

enableAlarmsActions

src/main/CloudwatchTools.ts:74-77

Enable all alarm actions

Parameters

Returns Promise<void>

AwsConfig

src/main/common-interfaces.ts:6-12

Base config used in all tool kits

ClusterState

src/main/constants.ts:6-11

Enum for describing the state of an RDS cluster

Type: number

StackReference

src/main/constants.ts:18-21

Enum for referencing blue or green stacks

Type: number

LambdaConfig

src/main/LambdaTools.ts:13-17

Extends AwsConfig

Configuration options for the Lambda toolkit

LambdaTools

src/main/LambdaTools.ts:29-172

Toolkit for Lambda operations

enableRule

src/main/LambdaTools.ts:93-95

Enables a lambda's cloudwatch events rule (ie, cron trigger)

Parameters

Returns Promise<void>

disableRule

src/main/LambdaTools.ts:103-105

Disables a lambda's cloudwatch events rule (ie, cron trigger)

Parameters

Returns Promise<void>

enableEventMapping

src/main/LambdaTools.ts:130-132

Enables a lambda's event mappings (eg, an SQS subscription)

Parameters

Returns Promise<void>

disableEventMapping

src/main/LambdaTools.ts:140-142

Disables a lambda's event mappings (eg, an SQS subscription)

Parameters

Returns Promise<void>

getVersion

src/main/LambdaTools.ts:151-155

Gets the currently running version of a lambda fn

Parameters

Returns Promise<string> The lambda version

getAlias

src/main/LambdaTools.ts:165-171

Returns details about a Lambda function alias.

Parameters
  • reference StackReference Reference to a lambda stack
  • Name string The name of the alias to return data about

Returns Promise<AliasConfiguration>

TopicData

src/main/SnsTools.ts:11-17

Parameters to describe an SNS topic subscription

SnsConfig

src/main/SnsTools.ts:30-33

Extends AwsConfig

Configuration options for the SNS toolkit

SnsTools

src/main/SnsTools.ts:60-118

Toolkit for SNS operations

enableSubscription

src/main/SnsTools.ts:105-107

Enables an SNS subscription

Parameters

Returns Promise<void>

disableSubscription

src/main/SnsTools.ts:115-117

Disables an SNS subscription

Parameters

Returns Promise<void>

SqsConfig

src/main/SqsTools.ts:12-15

Extends AwsConfig

Configuration options for the SQS toolkit

SqsTools

src/main/SqsTools.ts:27-65

Toolkit for SQS operations

purgeQueues

src/main/SqsTools.ts:51-64

Purges a queue pair (q and dlq) based on config and queue reference

Parameters

Returns Promise<void>

Current Tags

  • 1.8.1                                ...           latest (12 days ago)

11 Versions

  • 1.8.1                                ...           12 days ago
  • 1.8.0                                ...           14 days ago
  • 1.7.0                                ...           16 days ago
  • 1.6.0                                ...           22 days ago
  • 1.5.1                                ...           2 months ago
  • 1.5.0                                ...           2 months ago
  • 1.4.1                                ...           2 months ago
  • 1.4.0                                ...           2 months ago
  • 1.3.0                                ...           2 months ago
  • 1.2.0                                ...           2 months ago
  • 1.1.0                                ...           2 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 59
Last Day 0
Last Week 0
Last Month 33
Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |