8

I have this CDK code:

const logGroup = new LogGroup(this, 'MyAppLogGroup', {
  logGroupName: 'myapp',
  retention: RetentionDays.ONE_DAY
});

When I run cdk deploy, log group is created in CloudWatch, but when I run cdk destroy, it's not deleted. Is there some way to enable this?

Héctor
  • 24,444
  • 35
  • 132
  • 243

2 Answers2

12

See https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-logs.LogGroup.html#removalpolicy. You need to set the removalPolicy of the LogGroup to DESTROY as the default one is RETAIN

Milan Gatyás
  • 2,509
  • 1
  • 17
  • 23
6

Milan is 100% correct here, I'm just adding some example and more details about how to do it..

import * as cdk from "@aws-cdk/core";

const accessLogGroup = new LogGroup(this, 'MyAppLogGroup', {
    logGroupName: 'myapp',
    retention: RetentionDays.ONE_DAY,
    // This does the work:
    removalPolicy: core.RemovalPolicy.DESTROY
});
grepit
  • 21,260
  • 6
  • 105
  • 81
  • just quick nitpicking. Isn't it supposed to be `cdk.RemovalPolicy.DESTROY` instead of `core.RemovalPolicy.DESTROY`? Since you import the core as cdk. – addicted Jul 11 '22 at 14:42