CDK 销毁不会删除 S3 存储桶
S3 bucket is not removed by CDK destroy
比如我的CDK项目有S3 bucket,IAM角色,Lambda函数。
$ cdk bootstrap
$ cdk deploy
这将创建一个 S3 存储桶、IAM 角色和 Lambda 函数。
$ cdk destroy
它删除了 IAM 角色和 Lambda 函数,但保留了 S3 存储桶。
当然,S3 桶是空的。
这是正确的行为吗?如果是这样,除 S3 存储桶外,哪些资源将被保留?
该存储桶因其 RetentionPolicy 而被保留。来自 RetentionPolicy 上的 CDK 文档:
The removal policy controls what happens to the resource if it stops
being managed by CloudFormation.
Name
Description
DESTROY
This is the default removal policy.
RETAIN
This uses the 'Retain' DeletionPolicy, which will cause the resource to be retained in the account, but orphaned from the stack.
SNAPSHOT
This retention policy deletes the resource, but saves a snapshot of its data before deleting, so that it can be re-created later.
关于您关于保留哪些资源的问题:
Many stateful resources in the AWS Construct Library will accept a removalPolicy as a property, typically defaulting it to RETAIN.
通常,这包括 S3 存储桶、数据库资源等资源。
来自 S3 Buckets 的 AWS CDK 文档:
removalPolicy?
Type: RemovalPolicy (optional, default: The bucket will be orphaned.)
overview page 还有更多详细信息。
比如我的CDK项目有S3 bucket,IAM角色,Lambda函数。
$ cdk bootstrap
$ cdk deploy
这将创建一个 S3 存储桶、IAM 角色和 Lambda 函数。
$ cdk destroy
它删除了 IAM 角色和 Lambda 函数,但保留了 S3 存储桶。
当然,S3 桶是空的。
这是正确的行为吗?如果是这样,除 S3 存储桶外,哪些资源将被保留?
该存储桶因其 RetentionPolicy 而被保留。来自 RetentionPolicy 上的 CDK 文档:
The removal policy controls what happens to the resource if it stops being managed by CloudFormation.
Name | Description |
---|---|
DESTROY | This is the default removal policy. |
RETAIN | This uses the 'Retain' DeletionPolicy, which will cause the resource to be retained in the account, but orphaned from the stack. |
SNAPSHOT | This retention policy deletes the resource, but saves a snapshot of its data before deleting, so that it can be re-created later. |
关于您关于保留哪些资源的问题:
Many stateful resources in the AWS Construct Library will accept a removalPolicy as a property, typically defaulting it to RETAIN.
通常,这包括 S3 存储桶、数据库资源等资源。
来自 S3 Buckets 的 AWS CDK 文档:
removalPolicy?
Type: RemovalPolicy (optional, default: The bucket will be orphaned.)
overview page 还有更多详细信息。