【发布时间】:2019-10-27 09:43:08
【问题描述】:
我正在尝试以 JSON 格式设置一个支持 EC2 实例的 CloudFormation 模板,刚刚开始,但在选择 VPC 和子网时遇到了问题。最后,这将是一个跨多个帐户使用的模板,每个帐户具有多个 VCP 和子网。任何账户中都没有默认 VPC。
我想要 VPC 的模板提示,然后根据 VPC 迭代有效子网。我一直在处理这篇亚马逊博客文章:Looking up information on AWS CloudFormation stack parameters using AWS Lambda | AWS Management Tools Blog
但是,我似乎无法让它工作。如文章中所述,我使用正确的角色设置了 Lambda 函数,但我收到错误“此用户没有默认 VPC”。我也愿意采用更简单的方法来实现这一点。
{
"AWSTemplateFormatVersion":"2010-09-09",
"Description":"EC2 CloudFormation Template - Version 1.0",
"Metadata":{},
"Parameters":{
"InstanceType":{
"Description":"EC2 instance type",
"Type":"String",
"Default":"t2.small",
"AllowedValues":[
"t1.micro",
"t2.nano",
"t2.micro",
"t2.small",
"t2.medium",
"t2.large"
],
"ConstraintDescription":"must be a valid EC2 instance type."
},
"VpcName" : {
"Type" : "AWS::EC2::VPC::Id",
"Description" : "Select the VPC for this EC2 Instances"
},
"SubnetName" : {
"Type" : "AWS::EC2::Subnet::Id",
"Description" : "The list of SubnetIds"
}
},
"Mappings":{},
"Conditions":{},
"Resources":{
"VcpInfo" : {
"Type" : "Custom::VcpInfo",
"Properties" : {
"ServiceToken" : "arn:aws:lambda:us-east-1:206765214992:function:Test_GetAtt",
"NameFilter" : { "Ref": "VpcName" }
}
},
"SubnetInfo" : {
"Type" : "Custom::SubnetInfo",
"Properties" : {
"ServiceToken" : "arn:aws:lambda:us-east-1:206765214992:function:Test_GetAtt",
"NameFilter" : { "Ref": "SubnetName" }
}
},
"EOTSSEC2":{
"Type":"AWS::EC2::Instance",
"Properties":{
"DisableApiTermination":"false",
"ImageId":"ami-06bee8e1000e44ca4",
"InstanceType":{ "Ref":"InstanceType" },
"Monitoring":"true"
}
}
},
"Outputs":{
"VCPCidrBlock" : {
"Description" : "VCP CidrBlock",
"Value" : "!GetAtt VcpInfo.CidrBlock"
},
"SubnetAvailabilityZon" : {
"Description" : "Subnet AvailabilityZone",
"Value" : "!GetAtt SubnetInfo.AvailabilityZone"
},
"SubnetCidrBlock" : {
"Description" : "Subnet CidrBlock",
"Value" : "!GetAtt SubnetInfo.CidrBlock"
},
"SubnetVpcId" : {
"Description" : "Subnet VpcId",
"Value" : "!GetAtt SubnetInfo.VpcId"
}
}
}
我希望系统提示我输入 VPC,然后显示有效的子网列表。
【问题讨论】:
标签: json amazon-web-services amazon-ec2 amazon-cloudformation