Skip to main content

@otocolobus/aws-cdk-serverbluegreendeploymentgroup

Project description

EC2/On-Premise Server Blue/Green Deployment Group construct

GitHub Actions Workflow StatusNPM DownloadsNPM License

This construct creates a CodeDeploy Deployment Group for an EC2/On-Premises Deployment Group using the Blue/Green Deployment configuration.

ATTENTION: At the moment, this construct only supports the EC2 deployments with Auto Scaling Groups. The construct does not support neither the EC2 tag-based deployments nor the On-Premises tag-based deployments.

Table of Contents

Overview

Blue/Green deployments is popular deployment strategy that allows you to deploy your application to a new set of instances while keeping the old set of instances running. This allows you to switch traffic from the old set of instances to the new set of instances in a controlled manner.

This construct creates a CodeDeploy Deployment Group for an EC2 using the Blue/Green deployment configuration. The Deployment Group is associated with an Auto Scaling Group and a Load Balancer Target Group.

When a deployment is triggered, the Deployment Group will create a new Auto Scaling Group with the same configuration as the original Auto Scaling Group. The new Auto Scaling Group is called the Green Fleet. The Deployment Group will deploy the new revision of the application to the Green Fleet. After the deployment is successful, the Deployment Group will switch the traffic from the original Auto Scaling Group (Blue Fleet) to the Green Fleet. The Deployment Group will then terminate the instances in the original Auto Scaling Group (if configured to do so). The Deployment Group will wait for the original instances to be terminated before marking the deployment as successful.

You can configure the deployment to automatically rollback if the deployment fails, if the deployment is stopped, or if the deployment is in alarm.

Installation

NPM package: https://www.npmjs.com/package/@otocolobus/aws-cdk-serverbluegreendeploymentgroup

npm install @otocolobus/aws-cdk-serverbluegreendeploymentgroup

PyPI package: https://pypi.org/project/aws-cdk-serverbluegreendeploymentgroup/

pip install aws-cdk-serverbluegreendeploymentgroup

Usage

import { ServerBlueGreenDeploymentGroup } from "@otocolobus/aws-cdk-serverbluegreendeploymentgroup";

class MyStack extends Stack {
  constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);

    // ... other resources for LoadBalancer, AutoScalingGroup, etc.

    const application = new codedeploy.ServerApplication(this, "Application", {
      applicationName: "MyApplication",
    });

    // role required by CodeDeploy to do Blue/Green deployments with EC2 Auto Scaling Groups
    const role = new iam.Role(this, "Role", {
      assumedBy: new iam.ServicePrincipal("codedeploy.amazonaws.com"),
      managedPolicies: [
        iam.ManagedPolicy.fromAwsManagedPolicyName("service-role/AWSCodeDeployRole"),
      ],
      inlinePolicies: {
        ASGWithLaunchTemplate: new iam.PolicyDocument({
          statements: [
            new iam.PolicyStatement({
              actions: [
                "ec2:CreateTags",
                "ec2:RunInstances",
                "iam:PassRole",
                "ssm:GetParameters",
              ],
              resources: ["*"],
            }),
          ],
        }),
      },
    });

    const deploymentGroup = new ServerBlueGreenDeploymentGroup(
      this,
      "DeploymentGroup",
      {
        application,
        deploymentGroupName: "DeploymentGroup",
        role,
        loadBalancers: [
          codedeploy.LoadBalancer.application(loadBalancerTargetGroup),
        ],
        autoScalingGroups,
        // ... other optional properties
      },
    );

    // ... other resources for CodeDeploy and CodePipeline
    // where buildOutput is the output of the CodeBuild action

    pipeline.addStage({
      stageName: "Deploy",
      actions: [
        new codepipeline_actions.CodeDeployServerDeployAction({
          actionName: "Deploy",
          input: buildOutput,
          deploymentGroup,
        });
      ],
    });
  }
}

Limitations

Currently, it is not possible to update the Deployment Group name after the deployment group is created.

Currently, it is not possible to create a Deployment Group for an EC2 or On-Premises deployment with the tag-based configuration.

Author

Władysław Czyżewski (https://otocolobus.com)

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aws-cdk-serverbluegreendeploymentgroup-1.0.2.tar.gz (39.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file aws-cdk-serverbluegreendeploymentgroup-1.0.2.tar.gz.

File metadata

File hashes

Hashes for aws-cdk-serverbluegreendeploymentgroup-1.0.2.tar.gz
Algorithm Hash digest
SHA256 043c8c04147077b58ed5d58ecd859f739479f89d0ef43e229223eec0bd6f77ea
MD5 cb5d9af04920a292e01ca1a86ce0e1d8
BLAKE2b-256 9dd6358c1be84d244a02e06441fac1fdffd3663edccf64e942ea2e3016615fcc

See more details on using hashes here.

File details

Details for the file aws_cdk_serverbluegreendeploymentgroup-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for aws_cdk_serverbluegreendeploymentgroup-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ad05c421010ffe908d80c91ee8ad3708dd0a78845cebb5fecfc6b07b6159bef7
MD5 9343845d1d7c5dd4ec0836d1c19fcee4
BLAKE2b-256 c96288cccc774f0843cb5eb039b1fcb5b537a04bf42ddd2595029068045e3ab6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page