Intrinsic function references in DeletionPolicy and UpdateReplacePolicy attributes - AWS CloudFormation

Intrinsic function references in DeletionPolicy and UpdateReplacePolicy attributes

When you add the AWS::LanguageExtensions transform in a AWS CloudFormation template, you can use intrinsic functions to define the DeletionPolicy attribute and UpdateReplacePolicy attribute resource attributes.

Note

The intrinsic function must resolve to valid DeletionPolicy options or UpdateReplacePolicy options.

Declaration

JSON

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

YAML

DeletionPolicy: IntrinsicFunction
UpdateReplacePolicy: IntrinsicFunction

Parameters

IntrinsicFunction

The intrinsic function that resolves to a valid DeletionPolicy attribute or UpdateReplacePolicy attribute option.

Examples

Define the DeletionPolicy and UpdateReplacePolicy using the Fn:If intrinsic function

The following example sets the DeletionPolicy attribute and UpdateReplacePolicy attribute attributes based on the condition defined in the Fn::If intrinsic function. If the Stage parameter is Prod, the DeletionPolicy and UpdateReplacePolicy attributes will be set to 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

Define the DeletionPolicy and UpdateReplacePolicy attributes using the Ref intrinsic function

The following example sets the DeletionPolicy attribute and UpdateReplacePolicy attribute attributes based on the value resolved by the Ref intrinsic function. If the DeletionPolicyParam and UpdateReplacePolicyParam parameters are both set to Retain, the DeletionPolicy and UpdateReplacePolicy attributes are also set to 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

Supported functions

Within the DeletionPolicy or UpdateReplacePolicy attributes, you can use the following functions:

You can also use the following Pseudo parameters:

  • AWS::AccountId

  • AWS::Partition

  • AWS::Region