1 Risposta
- Più recenti
- Maggior numero di voti
- Maggior numero di commenti
0
【以下的回答经过翻译处理】 默认情况下,CDK通常为有状态的资源(比如DynamoDB的表)的RemovalPolicy 设置为RETAIN, 来避免在销毁堆栈时将其删除。
您可以在CDK合成模板中看到这一点。例如,使用 CDK 中声明的资源:
const table = new ddb.Table(this, "testTable", {
partitionKey: { type: AttributeType.STRING, name: 'id' },
});
合成的CloudFormation模板将包含以下内容:
"testTableFD9E8557": {
"Type": "AWS::DynamoDB::Table",
"Properties": {
[snip]
},
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain",
[snip]
},
CloudFormation UpdateReplacePolicy 和 [DeletionPolicy](https://docs.aws.amazon.com/AWSCloudFormation /latest/UserGuide/aws-attribute-deletionpolicy.html) 为“保留”的属性将导致 CloudFormation 在删除堆栈时保持资源完好无损。
要在删除堆栈时(运行 cdk destroy
时)删除资源,请在代码中将RemovalPolicy的值设置为 DESTROY
或 SNAPSHOT
:
const table = new ddb.Table(this, "testTable", {
partitionKey: { type: AttributeType.STRING, name: 'id' },
removalPolicy: RemovalPolicy.DESTROY,
});
以下是以上代码合成的CloudFormation模板, 请参考.
"testTableFD9E8557": {
"Type": "AWS::DynamoDB::Table",
"Properties": {
[snip]
},
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete",
[snip]
},
Contenuto pertinente
- AWS UFFICIALEAggiornata 2 anni fa
- AWS UFFICIALEAggiornata 2 anni fa
- AWS UFFICIALEAggiornata un anno fa