I have written a simple Cloudformation template to use "Mappings". Following is the code. I have logged into us-west-2a (west coast) and ran my template. I have 3 default subnets. The AMI I gave in the mapping section, was created by me:
I expected when I type us-west-2a as parameter, it should pick ami-fcccdf85 as per code below. But it says
Template error: Unable to get mapping for RegionMap::us-west-2::AMI"
"RegionMap" : {
"us-east-1" : { "AMI" : "ami-48b4bf31" },
"us-west-2a" : { "AMI" : "ami-fcccdf85" },
"us-west-1" : { "AMI" : "ami-48b4bf31" }
}
Code:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "EC2 Head Node Instance ",
"Parameters": {
"AvailabilityZone": {
"Description": "Availablity Zone",
"Type": "String"
},
"Region":{
"Description": "Dev/Test/Prod regions",
"Type": "String"
},
"Subnet": {
"Description": "subnet to launch virtual server in",
"Type": "AWS::EC2::Subnet::Id"
}
},
"Mappings" : {
"RegionMap" : {
"us-east-1" : { "AMI" : "ami-48b4bf31" },
"us-west-2a" : { "AMI" : "ami-fcccdf85" },
"us-west-1" : { "AMI" : "ami-48b4bf31" }
}
},
"Resources": {
"EC2Instance": {
"Type": "AWS::EC2::Instance",
"Properties": {
"ImageId" : { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "AMI" ]},
"SubnetId": {"Ref": "Subnet"},
"AvailabilityZone": {"Ref": "AvailabilityZone"},
"Tags": [
{
"Key": "Name",
"Value": "Head Node in DEV region"
}
]
}
}
},
"Outputs": {
"InstanceId": {
"Value": {"Ref": "EC2Instance"},
"Description": "ID of virtual server"
},
"PublicIPAddress": {
"Value": {"Fn::GetAtt": ["EC2Instance", "PublicIp"]},
"Description": "public IP address of virtual server"
}
}
}
Any suggestions please?
you typed "us-west-2a" remove the a should be "us-west-2" AMI are region specific and not AZ (availability zone) specific, in other words you have to specify a region.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With