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.59k stars 3.89k forks source link

(@aws-cdk/aws-certificatemanager): DnsValidatedCertificate.applyRemovalPolicy() not deleting CloudWatch log groups #15075

Closed clemans closed 2 years ago

clemans commented 3 years ago

Brief Description

When deploying a stack with a DnsValidatedCertificate construct, a log group is created with the following naming convention: /aws/lambda/stackName-acmConstructName-AbCdEf012345

Upon destroying the stack, these log groups (sometimes more are created over time) remain as orphaned. This is also true even when calling the method applyRemovalPolicy.

The result is that the user must manually delete these log groups after each time a new feature branch stack is destroyed.

Reproduction Steps

/* ACM Certificate */
  const certificate = new DnsValidatedCertificate(this, `cert${featureSuffix}`, {
      domainName: fqdn,
      hostedZone: { zoneName: domainRoot, hostedZoneId },
      validation: { method: ValidationMethod.DNS }
  })

  certificate.applyRemovalPolicy(RemovalPolicy.DESTROY)

/* Application Load Balancer Ec2 Service */
  const alb = new ApplicationLoadBalancedEc2Service(this, `alb${featureSuffix}`, {
      certificate,
      taskDefinition,
      ...
  })

/* Stack Log Group */
  const logGroup = new LogGroup(this, `logGroup${featureSuffix}`, {
      logGroupName: `/stackName${featureSuffix}/`,
      removalPolicy: RemovalPolicy.DESTROY,
      retention: RetentionDays.THREE_DAYS
  })

/* Stack Services */
  const taskDefinition = new Ec2TaskDefinition(this, `taskDef${featureSuffix}`, {
      ...
  })

  taskDefinition.addContainer(`container${featureSuffix}`, {
      logging: new AwsLogDriver({
         logGroup,
         streamPrefix: `/container       
      })
      ...
  })

What did you expect to happen?

A destroyed stack that had a certificate.applyRemovalPolicy(RemovalPolicy.DESTROY) declaration should in turn delete the log group /aws/lambda/stackName-acmConstructName-AbCdEf012345.

A destroyed stack that had a certificate.applyRemovalPolicy(RemovalPolicy.RETAIN) declaration should in turn retain the log group /aws/lambda/stackName-acmConstructName-AbCdEf012345.

What actually happened?

A destroyed stack that had a certificate.applyRemovalPolicy(RemovalPolicy.DESTROY) declaration does not delete the log group /aws/lambda/stackName-acmConstructName-AbCdEf012345. The log group remains orphaned and the user must manually delete the log group.

Environment


This is :bug: Bug Report

madeline-k commented 3 years ago

@njlynch I removed the cloudwatch label, since I think the fix for this will be entirely in the aws-certificatemanager module. I might take a stab at fixing this anyway though.

github-actions[bot] commented 2 years ago

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