- What you’ll learn: how to add a parameter for a bucket name, reference it from a resource using
!Ref, validate the template locally, and update a stack in the console. - Useful reference: CloudFormation parameters documentation.
- Parameters let you provide input at stack creation or update time.
- They improve template reusability and avoid embedding environment-specific values.

- Best practice: place the
Parameterssection near the top of the template (aboveResources) for readability and maintainability.
- Define a parameter named
InputBucketNamethat accepts a string and provides a helpful description.
- Replace the hard-coded bucket name with a reference to the
InputBucketNameparameter using!Ref:
S3 bucket names must be globally unique and conform to naming rules. Typical constraints include:
- 3–63 characters
- Lowercase letters, numbers, hyphens, and dots allowed (no underscores)
- Cannot be formatted as an IP address
- Must begin and end with a letter or number
Changing
BucketName in your template causes CloudFormation to replace the S3 bucket resource (CloudFormation cannot rename an existing bucket). Replacement deletes the old resource and creates a new one; deletion can fail if the original bucket is not empty. Take care when updating bucket names in an existing stack.- Use cfn-lint to validate the YAML template before uploading:
- In the console select the stack and choose Update stack → Replace current template → Upload a template file.
- Upload your updated template and click Next.
InputBucketName field and its description. This is where you provide the value that gets substituted into the template via !Ref.

- After submitting the update, wait for the stack to complete. On success, the stack status will show UPDATE_COMPLETE.

- Open the S3 console and refresh the bucket list. The bucket name you entered via the parameter will appear, and the tags defined in the template will be applied.

- Use CloudFormation Parameters to supply values at stack creation or update time instead of hard-coding them.
- Place
Parametersat the top of your template (aboveResources) for readability. - Use
!Refto reference parameter values insideResources. - Validate templates locally with
cfn-lintbefore deploying. - Ensure S3 bucket names meet naming constraints and be careful: changing a bucket name forces resource replacement.
| Resource | Purpose | Link |
|---|---|---|
| CloudFormation parameters | Reference and details | https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html |
| S3 bucket naming rules | Naming constraints and guidance | https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html |
| cfn-lint | Template validation tool | https://github.com/aws-cloudformation/cfn-lint |
| Updating stacks | Update stack workflow in CloudFormation | https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/updating-stacks.html |
- Use parameters for tags, versioning settings, or names of other resources to make templates flexible and environment-agnostic.