What you’ll learn
- How to add top-level Metadata to a CloudFormation template for documentation.
- How to expose an InstanceType as a Parameter with a dropdown (AllowedValues).
- How to reference the parameter with the intrinsic function
!Ref. - How to update a stack in the console and verify the resulting EC2 instance type.
Metadata
Add a top-level Metadata section near the top of the template. Metadata is for humans and auditing — CloudFormation doesn’t use top-level Metadata to change provisioning behavior, though resource-level Metadata can be used by helper tools (for example, cfn-init).Top-level Metadata is for humans and documentation. CloudFormation itself does not directly use top-level Metadata to change provisioning behavior, although resource-level Metadata can be consumed by helper tools (for example, cfn-init) to influence instance configuration.
Choosing which instance types to allow (research)
Before defining the parameter, decide which EC2 instance types you’ll expose (for example, free-tier eligible types or sizes that match your workload and cost constraints). You can inspect instance types in the EC2 console.

- t3.micro (often free-tier eligible)
- t3.small
Parameters — make InstanceType configurable
Create a parameter namedMyInstanceType (or another clear name). Add a Description and an AllowedValues list so the CloudFormation console presents a dropdown for selection.
| Field | Purpose | Example |
|---|---|---|
| Type | Data type for the parameter | String |
| Description | Short help text shown in the console | Select your EC2 instance type |
| AllowedValues | Limits choices; shows a dropdown in the console | t3.micro, t3.small |
| Default | Value used if the user doesn’t change the parameter | t3.micro |
!Ref when setting the EC2 InstanceType property. Below is a minimal complete template that includes Metadata, the Parameter, a Security Group allowing HTTP and SSH, and an EC2 instance that references the parameter.
The ImageId shown (ami-0eb9d6fc9fab44d24) is region-specific. Replace it with an AMI ID available in your target region (for example, an Amazon Linux 2 AMI). Also be aware that changing InstanceType may replace the instance (resulting in termination of the previous instance) depending on the property change behavior for EC2 instances.
Deploying or updating the stack
When creating or updating a stack in the CloudFormation console you can upload your template file or point to an S3 URL.
MyInstanceType parameter will show your Description and AllowedValues as a dropdown.

t3.small) and continue. CloudFormation will apply the change: it may modify the instance in place or replace it (terminating the previous instance and launching a new one) depending on the resource update behavior.
When the update completes successfully the stack will show an UPDATE_COMPLETE status.

t3.small). You may also see terminated instances from the previous configuration in the console.

t3.micro) — CloudFormation will apply the update and change the instance accordingly.
Viewing the template and Metadata
Auditors and operators can view the template and the Metadata you added from the CloudFormation console by selecting the stack and opening the template view.
Summary checklist
- Add a top-level Metadata section for documentation.
- Define a Parameter for InstanceType with Description, AllowedValues, and Default.
- Use
!Refto reference the parameter in the EC2 Instance resource. - Upload the template or provide an S3 URL in the CloudFormation console.
- Select the desired InstanceType during stack creation/update and verify the result in EC2.