我编写了一个简单的Cloudformation模板来使用“Mappings”。以下是代码。我已经登录了us-west-2a(西海岸)并运行了我的模板。我有3个默认子网。我在映射部分给出的AMI是由我创建的:
我预计当我输入us-west-2a作为参数时,它应该按照下面的代码选择ami-fcccdf85。但它说
模板错误:无法获取RegionMap :: us-west-2 :: AMI“
的映射 "RegionMap" : {
"us-east-1" : { "AMI" : "ami-48b4bf31" },
"us-west-2a" : { "AMI" : "ami-fcccdf85" },
"us-west-1" : { "AMI" : "ami-48b4bf31" }
}
代码:
{
"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"
}
}
}
有什么建议吗?
答案 0 :(得分:1)
您键入的“ us-west-2a”删除a应该是“ us-west-2” AMI是区域特定的,而不是AZ(可用区域)特定的,换句话说,您必须指定一个区域。