Explains how to use AWS CloudFormation parameters to set defaults, validate input, restrict allowed values, and reference parameters in resources like S3 buckets
In this lesson you’ll learn how to define CloudFormation Parameters to accept input, set sensible defaults, and constrain user choices. Parameters act as template inputs (form fields) and support validation through Type, Default, AllowedValues, and other properties. You’ll also see how to reference parameters (with !Ref or Ref) inside resources such as an S3 bucket.Parameters are useful for:
Reusing templates across environments (dev/stage/prod).
Pre-filling metadata like developer names or tags.
Restricting choices to avoid invalid configurations.
Parameters overviewA parameter entry defines the input name, its Type, and optional validation and UI hints such as Description, Default, and AllowedValues. These fields enforce validation both in the console and when you run linting tools locally.
Parameter field
Purpose
Example
Type
Determines the input data type (String, Number, AWS-specific types, etc.)
Simple example — referencing a parameter in an S3 bucketBelow is a minimal template that defines a parameter for the S3 bucket name and uses it in the bucket resource via !Ref:
Copy
Parameters: InputBucketName: Type: String Description: Please enter your desired S3 bucket nameResources: MyS3Bucket: Type: AWS::S3::Bucket Properties: BucketName: !Ref InputBucketName
Setting a default valueProviding a Default value pre-fills the parameter in the CloudFormation console so users don’t need to type the same metadata repeatedly. Defaults are especially handy for tags such as Developer or Environment.Example: add a developer parameter with a Default and use it in the bucket Tags via !Ref.
Copy
Parameters: InputBucketName: Type: String Description: Please enter your desired S3 bucket name InputDeveloperName: Type: String Default: Arno Pretorius Description: Name of the developerResources: MyS3Bucket: Type: AWS::S3::Bucket Properties: BucketName: !Ref InputBucketName Tags: - Key: Developer Value: !Ref InputDeveloperName - Key: Environment Value: "Development"
Validate your template locally before uploading:
Copy
cfn-lint s3-bucket.yaml
Use cfn-lint to catch syntax errors, unsupported properties, or policy issues before deploying—this can save time and reduce failed stack updates.
When you upload this template and choose Update stack → Replace existing template, CloudFormation will show the parameters page with the Default value pre-filled. The Default will be used unless you overwrite it in the console.
Limiting choices with AllowedValuesTo present a curated set of options to users (for example, a list of developers or environments), use AllowedValues. The CloudFormation console renders a dropdown containing only the specified values.
Copy
Parameters: InputBucketName: Type: String Description: Please enter your desired S3 bucket name InputDeveloperName: Type: String AllowedValues: - Arno Pretorius - Alice Description: Choose the developer responsible for this stackResources: MyS3Bucket: Type: AWS::S3::Bucket Properties: BucketName: !Ref InputBucketName Tags: - Key: Developer Value: !Ref InputDeveloperName - Key: Environment Value: "Development"
CloudFormation often displays the first AllowedValues entry as the initially-selected value in the dropdown. Be mindful of the ordering if you rely on which option is selected by default.
To update the stack with the modified template, choose Update stack → Replace existing template and upload the updated file.
After you select an AllowedValues entry and apply the update, CloudFormation passes that value to the parameter and the resource tags reflect the chosen developer. If the S3 console doesn’t immediately show the updated tags, try a hard refresh of the page.Summary — quick takeaways
Default: pre-fills a parameter value in the CloudFormation console to simplify deployments.
AllowedValues: restricts a parameter to a predefined set of valid choices and produces a dropdown in the console.
Reference parameters in resources using !Ref (or other intrinsic functions) to populate properties such as BucketName or Tags.
Validate templates locally with tools like cfn-lint before uploading.
Final example (parameters with AllowedValues and the referenced S3 resource):
Copy
Parameters: InputBucketName: Type: String Description: Please enter your desired S3 bucket name InputDeveloperName: Type: String AllowedValues: - Arno Pretorius - Alice Description: Choose the developer responsible for this stackResources: MyS3Bucket: Type: AWS::S3::Bucket Properties: BucketName: !Ref InputBucketName Tags: - Key: Developer Value: !Ref InputDeveloperName - Key: Environment Value: "Development"