CloudWatch 日志组未在 cdk destroy 上删除
CloudWatch log group is not deleted on cdk destroy
我有这个 CDK 代码:
const logGroup = new LogGroup(this, 'MyAppLogGroup', {
logGroupName: 'myapp',
retention: RetentionDays.ONE_DAY
});
当我 运行 cdk deploy
时,在 CloudWatch 中创建了日志组,但是当我 运行 cdk destroy
时,它没有被删除。有什么方法可以启用此功能吗?
参见https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-logs.LogGroup.html#removalpolicy。您需要将 LogGroup
的 removalPolicy
设置为 DESTROY
,因为默认设置为 RETAIN
Milan 在这里是 100% 正确的,我只是添加了一些例子和更多关于如何做的细节..
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
});
我有这个 CDK 代码:
const logGroup = new LogGroup(this, 'MyAppLogGroup', {
logGroupName: 'myapp',
retention: RetentionDays.ONE_DAY
});
当我 运行 cdk deploy
时,在 CloudWatch 中创建了日志组,但是当我 运行 cdk destroy
时,它没有被删除。有什么方法可以启用此功能吗?
参见https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-logs.LogGroup.html#removalpolicy。您需要将 LogGroup
的 removalPolicy
设置为 DESTROY
,因为默认设置为 RETAIN
Milan 在这里是 100% 正确的,我只是添加了一些例子和更多关于如何做的细节..
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
});