
- Ensures one or more resources are created only after specified resources finish creation.
- Accepts either a single logical resource name or a list of logical names.
- Impacts deletion order because CloudFormation deletes resources in reverse creation order.
- Is useful when there is no direct reference relationship between dependent resources.
| Feature | Behavior | Example use case |
|---|---|---|
| Accepts single or list | Use a string or an array of logical names | A bucket and multiple resources that must be created after it |
| Creation order control | Forces sequential creation where implicit dependencies are absent | Linking a resource that relies on an external resource created in the same stack |
| Deletion order | Resources are deleted in reverse order of creation | Prevents deleting a dependent resource before the resource it needs |
| Implicit dependencies | Referencing a resource (e.g., !Ref, !GetAtt) creates implicit dependency | Most property references already enforce ordering without DependsOn |
- “MyBucket” and “BucketPolicy” are logical resource names in the same CloudFormation template.
- The Bucket property uses
!Refto reference the bucket name. - The PolicyDocument grants the public principal (
"*") thes3:GetObjectaction for all objects in the bucket by using!Subto construct the bucket ARN.
Note: CloudFormation automatically creates implicit dependencies when a resource is referenced (for example, using
!Ref or !GetAtt). In many cases (including this example where Bucket: !Ref MyBucket is used), explicit DependsOn is unnecessary. Use DependsOn when you need to enforce ordering but there is no property reference or when you must control a precise creation/deletion sequence.Warning: Overusing DependsOn can make templates harder to maintain and slower to deploy because it forces sequential creation. Prefer implicit dependencies where possible. Use DependsOn sparingly—only when implicit references cannot express the required ordering.
- AWS CloudFormation documentation: DependsOn attribute
- AWS CloudFormation best practices
- Amazon S3 documentation