How do I use multiple values for individual parameters in an AWS CloudFormation template?
Last updated: 2020-08-20
I want to create or update a stack from an AWS CloudFormation template using multiple values for individual parameters.
Short description
You can pass multiple values for individual parameters in an AWS CloudFormation template in the following ways:
- Use AWS-specific parameter types to select values from a pre-populated list of existing AWS values from an AWS account
- Use CommaDelimitedList parameter types to specify your own values
Resolution
Use AWS-specific parameter types to select values from a pre-populated list of existing AWS values from an AWS account
Important: AWS CloudFormation validates the input value that you select against existing values in your account.
In the following sample AWS CloudFormation templates, the parameter with the SecurityGroups key specifies an AWS-specific parameter type that can accept multiple values for SecurityGroupIds.
JSON template:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"SecurityGroups": {
"Type": "List<AWS::EC2::SecurityGroup::Id>",
"Description": "The list of SecurityGroupIds in your Virtual Private Cloud (VPC)"
}
},
"Resources": {
"MyEC2Instance": {
"Type": "AWS::EC2::Instance",
"Properties": {
"ImageId": "ami-79fd7eee",
"KeyName": "testkey",
"SecurityGroupIds": {
"Ref": "SecurityGroups"
}
}
}
}
}
YAML template:
AWSTemplateFormatVersion: 2010-09-09
Parameters:
SecurityGroups:
Type: 'List<AWS::EC2::SecurityGroup::Id>'
Description: The list of SecurityGroupIds in your Virtual Private Cloud (VPC)
Resources:
MyEC2Instance:
Type: 'AWS::EC2::Instance'
Properties:
ImageId: ami-79fd7eee
KeyName: testkey
SecurityGroupIds: !Ref SecurityGroups
Use CommaDelimitedList parameter types to enter input values
In the following sample AWS CloudFormation templates, the parameter with the SecurityGroups key specifies a CommaDelimitedList type that can accept multiple values for SecurityGroupIds.
JSON template:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"SecurityGroups": {
"Type": "CommaDelimitedList",
"Description": "The list of SecurityGroupIds in your Virtual Private Cloud (VPC)",
"Default": "sg-a123fd85, sg-b456ge94"
}
},
"Resources": {
"MyEC2Instance": {
"Type": "AWS::EC2::Instance",
"Properties": {
"ImageId": "ami-79fd7eee",
"KeyName": "testkey",
"SecurityGroupIds": {
"Ref": "SecurityGroups"
}
}
}
}
}
YAML template:
AWSTemplateFormatVersion: 2010-09-09
Parameters:
SecurityGroups:
Type: CommaDelimitedList
Description: The list of SecurityGroupIds in your Virtual Private Cloud (VPC)
Default: sg-a123fd85, sg-b456ge94
Resources:
MyEC2Instance:
Type: 'AWS::EC2::Instance'
Properties:
ImageId: ami-79fd7eee
KeyName: testkey
SecurityGroupIds: !Ref SecurityGroups
Related information
Did this article help?
Do you need billing or technical support?