Search⌘ K

CloudFormation Features: Part II

Explore advanced AWS CloudFormation features such as CreatePolicy and UpdatePolicy to control resource creation and updates. Learn how stack policies safeguard resources, manage multi-account deployments with StackSets, and import existing resources to CloudFormation. Understand the differences between CloudFormation and Elastic Beanstalk to efficiently automate and manage your AWS infrastructure.

CreatePolicy

The CreatePolicy attribute can be used with a resource to prevent its status from reaching the create complete state until AWS CloudFormation receives a certain number of signals from the resource. The CreatePolicy attribute is only supported by the following resource types:

  • AWS::AppStream::Fleet
  • AWS::AutoScaling::AutoScalingGroup
  • AWS::EC2::Instance
  • AWS::CloudFormation::WaitCondition

In the following code, we have a resource, EducativeASG, with desired capacity 3. We’ve associated a creation policy with this ASG to ensure that CloudFormation receives three SUCCESS signals, one from each of the ASG instances.

YAML
EducativeASG:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
AvailabilityZones:
Fn::GetAZs: ''
LaunchConfigurationName:
Ref: LaunchConfig
DesiredCapacity: '3' # Create 3 instances in the Auto Scaling group
MinSize: '1'
MaxSize: '10'
CreationPolicy:
ResourceSignal:
Count: '3' # Ensure that all three instances created by the ASG sent the 'SUCCESS' signal
Timeout: PT15M # Specifies the timeout for the CreationPolicy

UpdatePolicy

We can use UpdatePolicy to specify how CloudFormation should update a resource. The UpdatePolicy attribute is supported for the following resource types in CloudFormation:

  • AWS::AppStream::Fleet
  • AWS::AutoScaling::AutoScalingGroup
  • AWS::ElastiCache::ReplicationGroup
  • AWS::OpenSearchService::Domain
...