Explains AWS CloudFormation parameters, their types, usage, and examples to make templates configurable, reusable, and safe across environments.
Welcome to the lesson on CloudFormation parameters. This guide explains what parameters are, why they’re important, and how to declare and reference them in a CloudFormation template. By the end you’ll understand how to make templates configurable and reusable across environments.
Parameters are input values you declare in the Parameters section of a CloudFormation template. They act like template variables that let users or automation customize a stack at creation or update time.Common parameter uses:
Below is a minimal CloudFormation YAML example that declares a parameter named InputBucketName and uses !Ref to set the BucketName property of an S3 bucket resource.
Copy
Parameters: InputBucketName: Type: String Description: Please enter your desired S3 bucket nameResources: MyS3Bucket: Type: AWS::S3::Bucket Properties: BucketName: !Ref InputBucketName
How this works (step-by-step)
When you launch the stack, provide a value for the InputBucketName parameter (for example, my-app-bucket-prod).
CloudFormation creates the MyS3Bucket resource.
The template uses !Ref InputBucketName to insert the parameter value as the BucketName property. The resulting bucket will have the name you provided.
Remember: S3 bucket names must be globally unique and comply with AWS naming rules (lowercase letters, numbers, hyphens, no uppercase or underscores, etc.). If the provided name is invalid or already taken, stack creation will fail.