aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.36k stars 3.77k forks source link

codedeploy: cannot configure blue/green deployment for ServerDeploymentGroup #30555

Open daTobiGit opened 3 weeks ago

daTobiGit commented 3 weeks ago

Describe the bug

There are no options in CDK to set the deployment type from inplace to blue/green deployment. On the console, you can easily switch

Expected Behavior

i expected some configuration options in the class ServerDeploymentGroup, but there are none.

Current Behavior

only inplace deployments are possible

Reproduction Steps

this is all that can be configured:

`const vpc = new Vpc(this, "connect4-vpc-ec2", { vpcName: "connect4-vpc-ec2", maxAzs: 2, subnetConfiguration: [ { cidrMask: 24, name: 'ingress', subnetType: SubnetType.PUBLIC, }] })

    const asgC4Backend = new AutoScalingGroup(this, "asg", {
        vpc,
        instanceType: InstanceType.of(InstanceClass.BURSTABLE2, InstanceSize.MICRO),
        machineImage: MachineImage.latestAmazonLinux2023(),
        desiredCapacity: 2,
        minCapacity: 1,
        maxCapacity: 3
    })
    Tags.of(asgC4Backend).add("id", "backend-server")
    asgC4Backend.role.addManagedPolicy(ManagedPolicy.fromAwsManagedPolicyName('AdministratorAccess'))

    const nlb = new NetworkLoadBalancer(this, 'C4-NLB', {
        vpc,
        internetFacing: true,
    });

    const listener = nlb.addListener('Listener', {
        port: 8001,
    });

    // Add the Auto Scaling Group as a target
    const nlbTargetGroup = listener.addTargets('Targets', {
        port: 8001,
        targets: [asgC4Backend],
    });

    const serverApplication = new ServerApplication(this, "serverApplication", {
        applicationName: "connect4-server-application-ec2"
    })

    const deploymentGroup = new ServerDeploymentGroup(this, 'deploymentGroupC4Backend', {
        application: serverApplication,
        deploymentGroupName: 'deploymentGroupC4Backend',
        autoScalingGroups: [asgC4Backend],
        installAgent: true,
        deploymentConfig: ServerDeploymentConfig.ALL_AT_ONCE,
        loadBalancers: [
            LoadBalancer.network(nlbTargetGroup),
        ],
        // auto-rollback configuration
        autoRollback: {
            failedDeployment: true, // default: true
        },
    });
    deploymentGroup.role?.addManagedPolicy(ManagedPolicy.fromAwsManagedPolicyName('AdministratorAccess'))`

Possible Solution

include configuration options for blue/green deployment to the ServerDeploymentGroup

Additional Information/Context

No response

CDK CLI Version

2.144.0 (build 5fb15bc)

Framework Version

No response

Node.js Version

v20.13.1

OS

amazon linux 2023

Language

TypeScript

Language Version

Typescript (5.4.5)

Other information

No response

daTobiGit commented 3 weeks ago

it seems the aws cli does support those parameters:

aws deploy create-deployment-group \ --application-name MyCodeDeployApp \ --deployment-group-name MyDeploymentGroup \ --deployment-config-name CodeDeployDefault.AllAtOnce \ --auto-scaling-groups MyAutoScalingGroup \ --service-role-arn arn:aws:iam::123456789012:role/CodeDeployRole \ --deployment-style deploymentType=BLUE_GREEN,deploymentOption=WITH_TRAFFIC_CONTROL \ --blue-green-deployment-configuration file://blue-green-deployment-config.json \ --load-balancer-info elbInfoList=[{name=MyLoadBalancer}]

khushail commented 3 weeks ago

Hi @daTobiGit , thanks for reaching out.

I see that cloudformation supports this blue/green deployment , can be seen here in L1 Construct -

https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codedeploy.CfnDeploymentGroup.html#bluegreendeploymentconfiguration

Is this what you are looking for ??

github-actions[bot] commented 3 weeks ago

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

daTobiGit commented 2 weeks ago

Hi @khushail , thank you for your response.

i already tried it out with the cfn class, but unfortunately it also doesnt work

   `// const roleC4DeploymentApp = new Role(this, "roleC4DeploymentApp", {
    //     assumedBy: new ServicePrincipal('codedeploy.amazonaws.com'),
    //     managedPolicies: [
    //         ManagedPolicy.fromAwsManagedPolicyName('AdministratorAccess'),
    //     ],
    // });
    // const serverApplication2 = new ServerApplication(this, "serverApplicationEC2Deploy", {
    //     applicationName: "c4ec2deploymentApp"
    // })
    // const dg2 = new CfnDeploymentGroup( this, "dg2",{
    //     applicationName: serverApplication2.applicationName,
    //     deploymentGroupName: 'C4BackendDeployment',
    //     // deploymentConfigName: 'deploymentConfigName',
    //     serviceRoleArn: roleC4DeploymentApp.roleArn,

    //     autoRollbackConfiguration: {
    //         enabled: true,
    //         events: ['DEPLOYMENT_FAILURE'],
    //     },
    //     autoScalingGroups: [asgC4Backend.autoScalingGroupName],
    //     blueGreenDeploymentConfiguration: {
    //         deploymentReadyOption: {
    //             actionOnTimeout: 'CONTINUE_DEPLOYMENT',
    //             waitTimeInMinutes: 0, // Immediate switch
    //         },
    //         greenFleetProvisioningOption: {
    //             action: 'COPY_AUTO_SCALING_GROUP',
    //         },
    //         terminateBlueInstancesOnDeploymentSuccess: {
    //             action: 'TERMINATE',
    //             terminationWaitTimeInMinutes: 1,
    //         },
    //     },

    //     // loadBalancerInfo: {
    //     //     targetGroupPairInfoList: [{
    //     //         targetGroups: [{ name: nlbTargetGroup.targetGroupName }],
    //     //         prodTrafficRoute: {
    //     //             listenerArns: [listener.listenerArn],
    //     //         },
    //     //         testTrafficRoute: {
    //     //             listenerArns: [listener.listenerArn],
    //     //         },
    //     //     }],
    //     // },

    //     deploymentStyle: {
    //         deploymentOption: 'WITH_TRAFFIC_CONTROL',
    //         deploymentType: 'BLUE_GREEN',
    //     }
    // })
    // const deploymentGroup2 = ServerDeploymentGroup.fromServerDeploymentGroupAttributes( this, 'ExistingCodeDeployDeploymentGroup', {
    //     application : serverApplication2,
    //     deploymentGroupName: dg2.ref,
    // });`

when i configure the "deploymentStyle" attribute, i must not specify the AutoScalingGroups , LoadBalancerInfo , or Deployment properties. But CDK says: "one ASG has to be configured". This problem seems to be known: aws repost

khushail commented 2 weeks ago

My Bad, thanks for sharing the article. I see the CDK Docs also mention about this -

Amazon ECS blue/green deployments through CodeDeploy do not use the AWS::CodeDeploy::DeploymentGroup resource. To perform Amazon ECS blue/green deployments, use the AWS::CodeDeploy::BlueGreen hook. See [Perform Amazon ECS blue/green deployments through CodeDeploy using AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/blue-green.html) for more information.

In that case, you could file a FR with Cloudformation team ,by adding this on their Cloudformation coverage roadmap. .

let me know if you need any other help! Thanks!

daTobiGit commented 2 weeks ago

https://github.com/aws-cloudformation/cloudformation-coverage-roadmap/issues/2071