DeletionPolicy 和 UpdateReplacePolicy 屬性中的內部函數參考 - AWS CloudFormation

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

DeletionPolicyUpdateReplacePolicy 屬性中的內部函數參考

當您在 AWS CloudFormation 範本中新增AWS::LanguageExtensions轉換時,您可以使用內建函數來定義DeletionPolicy 屬性UpdateReplacePolicy 屬性資源屬性。

注意

內部函數必須解析為有效 DeletionPolicy 選項 或者 UpdateReplacePolicy 選項

宣告

JSON

{ "DeletionPolicy": IntrinsicFunction }
{ "UpdateReplacePolicy": IntrinsicFunction }

YAML

DeletionPolicy: IntrinsicFunction
UpdateReplacePolicy: IntrinsicFunction

參數

IntrinsicFunction

解析為有效 DeletionPolicy 屬性UpdateReplacePolicy 屬性 選項的內部函數。

範例

使用 Fn:If 內部函數來定義 DeletionPolicyUpdateReplacePolicy

下列範例依據 Fn::If 內部函數中定義的條件設定 DeletionPolicy 屬性UpdateReplacePolicy 屬性 屬性。如果 Stage 參數為 Prod,則 DeletionPolicyUpdateReplacePolicy 屬性將設定為 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 內部函數來定義 DeletionPolicyUpdateReplacePolicy 屬性

下列範例依據 Ref 內部函數所解析的值設定 DeletionPolicy 屬性UpdateReplacePolicy 屬性 屬性。如果 DeletionPolicyParamUpdateReplacePolicyParam 參數均設定為 Retain,則 DeletionPolicyUpdateReplacePolicy 屬性也會設定為 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

支援的函數

借助 DeletionPolicyUpdateReplacePolicy 屬性,您可以使用下列函數:

您也可以使用下列虛擬參數

  • AWS::AccountId

  • AWS::Partition

  • AWS::Region