CloudWatch log group is not deleted on cdk destroy

Viewed 2872

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?

2 Answers

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
});
Related