2 Answers
- Newest
- Most votes
- Most comments
0
How about this? I have not tested the template.
Mappings:
RegionMap:
us-east-1:
AMI: "ami-066f487d3b6819b0d"
Subnets: ["subnet-0e6f12f64042ea5b1"]
us-east-2:
AMI: "ami-0aef5e0adcbc7cc0f"
Subnets: ["subnet-0e6f12f64042ea5b1", "subnet-0bc661bb8d98f3f03"]
Resources:
autoscaling:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
AutoScalingGroupName: asg1
VPCZoneIdentifier: !FindInMap [RegionMap, !Ref "AWS::Region", Subnets]
I added the following on 2022-12-10.
I verified that the stack creation completes successfully using the following template. I confirmed with us-east-1 and us-east-2. Note: I changed the AMI IDs and Subnet IDs to the values of my AWS account.
AWSTemplateFormatVersion: "2010-09-09"
Mappings:
RegionMap:
us-east-1:
AMI: "ami-0b0dcb5067f052a63"
Subnets: ["subnet-xxxxx28b"] # mask
us-east-2:
AMI: "ami-0beaa649c482330f7"
Subnets: ["subnet-xxxxxb61", "subnet-xxxxx9e5"] # mask
Resources:
autoscaling:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
LaunchTemplate:
LaunchTemplateId: !Ref myLaunchTemplate
Version: !GetAtt myLaunchTemplate.LatestVersionNumber
MaxSize: "1"
MinSize: "0"
DesiredCapacity: "1"
VPCZoneIdentifier: !FindInMap [RegionMap, !Ref "AWS::Region", Subnets]
myLaunchTemplate:
Type: AWS::EC2::LaunchTemplate
Properties:
LaunchTemplateName: launch-template-test
LaunchTemplateData:
ImageId: !FindInMap [RegionMap, !Ref "AWS::Region", AMI]
InstanceType: t2.micro
answered a year ago
0
Hello, for error "Value of property VPCZoneIdentifier must be of type List of String", consider removing [ ] enclosing the subnets in the Mappings section. Also, the following template can be used in both us-east-1 and us-east-2 regions that you can consider testing:
Note: Displayed limited resource properties for simplicity. Make sure to add the required properties and replace your subnets IDs and AMI IDs.
Mappings:
RegionMap:
us-east-1:
AMI: ami-xxxx
Subnets: "subnet-xxxx"
us-east-2:
AMI: ami-xxxx
Subnets: "subnet-xxxx, subnet-xxxxx"
Parameters:
region:
Type: String
AllowedValues:
- us-east-1
- us-east-2
Conditions:
UE1: !Equals
- !Ref region
- us-east-1
Resources:
autoscaling:
Type: 'AWS::AutoScaling::AutoScalingGroup'
Properties:
AutoScalingGroupName: name-of-asg
VPCZoneIdentifier:
- !If
- UE1
- !FindInMap
- RegionMap
- !Ref region
- Subnets
- !FindInMap
- RegionMap
- !Ref region
- Subnets
#with other required properties in this resource type
Relevant content
- asked 5 years ago
- Accepted Answerasked 4 years ago
- asked 2 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago
Thank you for your response. I had initially tried it but ran it a problem while creating it with the following error.
"Value of property VPCZoneIdentifier must be of type List of String"
@learner00 I added the template I verified to my answer. The template worked as expected. If you could share the entire template with us, it might help us figure out the cause of your error.