DeletionPolicy
和 UpdateReplacePolicy
属性中的内置函数引用
在 AWS CloudFormation 模板中添加 AWS::LanguageExtensions
转换时,您可以使用内部函数来定义 DeletionPolicy 属性
和 UpdateReplacePolicy 属性
资源属性。
注意
内部函数必须解析为有效的 DeletionPolicy 选项
或 UpdateReplacePolicy 选项
。
声明
JSON
{ "DeletionPolicy":
IntrinsicFunction
}
{ "UpdateReplacePolicy":
IntrinsicFunction
}
YAML
DeletionPolicy:
IntrinsicFunction
UpdateReplacePolicy:
IntrinsicFunction
参数
IntrinsicFunction
-
解析为有效
DeletionPolicy 属性
或UpdateReplacePolicy 属性
选项的内置函数。
示例
使用 Fn:If
内置函数定义 DeletionPolicy
和 UpdateReplacePolicy
以下示例根据 Fn::If
内部函数中定义的条件设置 DeletionPolicy 属性
和 UpdateReplacePolicy 属性
属性。如果 Stage
参数为 Prod
,则 DeletionPolicy
和 UpdateReplacePolicy
属性将设置为 Retain
。
JSON
{ "AWSTemplateFormatVersion": "2010-09-09", "Transform": "AWS::LanguageExtensions", "Parameters": { "Stage": { "Type": "String", "AllowedValues": [ "Prod", "Staging", "Dev" ] } }, "Conditions": { "IsProd": { "Fn::Equals": [ { "Ref": "Stage" }, "Prod" ] } }, "Resources": { "Table": { "Type": "AWS::DynamoDB::Table", "Properties": { "KeySchema": [{ "AttributeName": "primaryKey", "KeyType": "HASH" }], "AttributeDefinitions": [{ "AttributeName": "primaryKey", "AttributeType": "S" }] }, "DeletionPolicy": { "Fn::If": [ "IsProd", "Retain", "Delete" ] }, "UpdateReplacePolicy": { "Fn::If": [ "IsProd", "Retain", "Delete" ] } } } }
YAML
AWSTemplateFormatVersion: 2010-09-09 Transform: 'AWS::LanguageExtensions' Parameters: Stage: Type: String AllowedValues: - Prod - Staging - Dev Conditions: IsProd: !Equals - !Ref Stage - Prod Resources: Table: Type: 'AWS::DynamoDB::Table' Properties: KeySchema: - AttributeName: primaryKey KeyType: HASH AttributeDefinitions: - AttributeName: primaryKey AttributeType: S DeletionPolicy: !If - IsProd - Retain - Delete UpdateReplacePolicy: !If - IsProd - Retain - Delete
使用 Ref
内置函数定义 DeletionPolicy
和 UpdateReplacePolicy
属性
以下示例根据 Ref
内部函数解析的值设置 DeletionPolicy 属性
和 UpdateReplacePolicy 属性
属性。如果 DeletionPolicyParam
和 UpdateReplacePolicyParam
参数均设置为 Retain
,则 DeletionPolicy
和 UpdateReplacePolicy
属性也设置为 Retain
。
JSON
{ "AWSTemplateFormatVersion": "2010-09-09", "Transform": "AWS::LanguageExtensions", "Parameters": { "DeletionPolicyParam": { "Type": "String", "AllowedValues": [ "Delete", "Retain", "Snapshot" ], "Default": "Delete" }, "UpdateReplacePolicyParam": { "Type": "String", "AllowedValues": [ "Delete", "Retain", "Snapshot" ], "Default": "Delete" } }, "Resources": { "Table": { "Type": "AWS::DynamoDB::Table", "Properties": { "KeySchema": [ { "AttributeName": "primaryKey", "KeyType": "HASH" }], "AttributeDefinitions": [{ "AttributeName": "primaryKey", "AttributeType": "S" }] }, "DeletionPolicy": { "Ref": "DeletionPolicyParam" }, "UpdateReplacePolicy": { "Ref": "UpdateReplacePolicyParam" } } } }
YAML
AWSTemplateFormatVersion: 2010-09-09 Transform: 'AWS::LanguageExtensions' Parameters: DeletionPolicyParam: Type: String AllowedValues: - Delete - Retain - Snapshot Default: Delete UpdateReplacePolicyParam: Type: String AllowedValues: - Delete - Retain - Snapshot Default: Delete Resources: Table: Type: 'AWS::DynamoDB::Table' Properties: KeySchema: - AttributeName: primaryKey KeyType: HASH AttributeDefinitions: - AttributeName: primaryKey AttributeType: S DeletionPolicy: !Ref DeletionPolicyParam UpdateReplacePolicy: !Ref UpdateReplacePolicyParam
支持的函数
在 DeletionPolicy
或 UpdateReplacePolicy
属性中,您可以使用以下函数:
您还可以使用以下伪参数:
-
AWS::AccountId
-
AWS::Partition
-
AWS::Region