aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

aws-cdk-lib.aws_ecs_patterns: service deployment not updating to latest revision

Open shawnwang-avl opened this issue 3 years ago • 4 comments

Describe the bug

When using ContainerImage.fromDockerImageAsset(asset) in ApplicationLoadBalancedFargateService, CDK deployment results in generation of a new task definition revision, referencing the newly pushed Docker image in CDK-managed ECR. But ECS service does not update this, and still remain on the INACTIVE task definition.

This is also observed in our aws-cdk-lib.pipelines: after passing Assets stage and Deployment stage, despite EcsService.Prepare and step and EcsService.Deploy deployment stages show successful, ECS service remain on the old INACTIVE task definition.

We are working around this issue by manually clicking the 'Update' service button in ECS console. But it defeats the purpose of a CI/CD pipeline.

Expected Behavior

When using ContainerImage.fromDockerImageAsset(asset), CDK pipeline is expected to deploy the newly produced task definition revision.

Current Behavior

a deployment is not triggered.

Reproduction Steps

Here is my ECS definition


export class EcsServiceStack extends Stack {

  constructor(scope: Construct, id: string, props: EcsServiceStackProps) {

    const asset = new DockerImageAsset(this, 'ServiceImage', {
      directory: path.join(__dirname, '..', '..', '..'),
      buildArgs: {
        // unfortunately can't retrieve from SecretsManager https://github.com/aws/aws-cdk/issues/14395
        SSH_PRIVATE_KEY: GITHUB_PRIVATE_KEY_BASE_64,
      },
    });

    const service = new ApplicationLoadBalancedFargateService(this, 'Service', {
      assignPublicIp: true,
      circuitBreaker: { rollback: false }, // see https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DeploymentCircuitBreaker.html
      cluster,
      cpu: cpuUnits,
      memoryLimitMiB: memoryMiB,
      deploymentController: {
        type: DeploymentControllerType.CODE_DEPLOY, // blue/green deployment model powered by AWS CodeDeploy
      },
      desiredCount: 1,
      taskImageOptions: {
        containerName: SERVICE_NAME,
        image: ContainerImage.fromDockerImageAsset(asset),
        environment: {
          STAGE: stage,
          PORT: INTERNAL_HTTP_PORT.toString(),
          HEALTH_CHECK_PATH: HEALTH_CHECK_PATH,
        },
        enableLogging: true,
        logDriver: new AwsLogDriver({
          streamPrefix: 'service',
          logGroup: new LogGroup(this, `${ SERVICE_NAME }ApplicationLogGroup`),
        }),
        taskRole: serviceExecutionRole,
        containerPort: INTERNAL_HTTP_PORT,
      },
      loadBalancerName: `${ stage }-ALB`,
      maxHealthyPercent: 200,
      minHealthyPercent: stage === STAGE.ALPHA ? 0 : 100, // speed up deployment in dev testing
      openListener: true,
      publicLoadBalancer: true,
      serviceName: `${ stage }-${ SERVICE_NAME }`,
      targetProtocol: ApplicationProtocol.HTTP, // ALB to server
      protocol: props.enableHttps ? ApplicationProtocol.HTTPS : ApplicationProtocol.HTTP, // client to ALB
      listenerPort: props.enableHttps ? HTTPS_PORT : HTTP_PORT,
      certificate: props.enableHttps ? props.dns?.acmCertificate : undefined,
      domainName: props.enableHttps ? serviceHostedZone!.zoneName : undefined,
      domainZone: props.enableHttps ? serviceHostedZone! : undefined,
    });

  }

CDK Pipeline adds this stack as part of a deployment stage.

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

5.45.0 (build af1fb7c)

Framework Version

No response

Node.js Version

v16.17.0

OS

MacOS Monterey 12.5.1

Language

Typescript

Language Version

TypeScript (4.9.3)

Other information

No response

shawnwang-avl avatar Dec 16 '22 06:12 shawnwang-avl

Hi, @madeline-k , any updates?

shawnwang-avl avatar Dec 21 '22 01:12 shawnwang-avl

the issue seems to be related to using type: DeploymentControllerType.CODE_DEPLOY

Switching to type: DeploymentControllerType.ECS seemed to help.

My understanding is, with CDK pipeline, we can't use CODE_DEPLOY anyways (ref)

Feel free to close this issue.

shawnwang-avl avatar Dec 23 '22 06:12 shawnwang-avl

Thanks for the update @shawnwang-avl!

peterwoodworth avatar Feb 01 '23 22:02 peterwoodworth

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

github-actions[bot] avatar Feb 01 '23 22:02 github-actions[bot]