从文档Fn:GetAtt,您只能检索Subnet的AvailabilityZone和Ipv6CidrBlocks详细信息。在CFn模板中没有内置的支持来获得给定子网的VpcId。
虽然有一个解决办法。如果使用的是aws-cli documentation,则可以使用describe-subnets
方法获取所需子网的VpcId,并将其作为输入传递给Cloudformation模板create_stack
调用。
即使您使用的是任何SDK,此方法仍然有效。例如,在Java中。
//pseudo code only!
DescribeSubnetsRequest request = new DescribeSubnetsRequest();
request.withSubnetIds("subnet-abcdefgh");
DescribeSubnetsResult result = awsClient.describeSubnets(request);
String myVpc = result.getSubnets().get(0).getVpcId();
// add the above VPC Id to the parameters of your Cloud formation template create stack request.
希望这会有所帮助。
这将是一个有用的功能,但我不相信CloudFormation有一个本地的方式来做到这一点。如果它足够重要,也许您可以使用Lambda支持的自定义资源来执行查找(类似示例:http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/walkthrough-custom-resources-lambda-lookup -amiids.html)。 – jarmod