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
and
UpdateReplacePolicy
resource attributes.
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 or UpdateReplacePolicy option.
Examples
Define the DeletionPolicy and UpdateReplacePolicy using the Fn:If intrinsic function
The following example sets the DeletionPolicy
and
UpdateReplacePolicy
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
and
UpdateReplacePolicy
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:
-
Fn::FindInMap
-
Fn::If
-
Ref
You can also use the following Pseudo parameters:
-
AWS::AccountId
-
AWS::Partition
-
AWS::Region