如何在CloudFormation脚本中引用现有VPC的VPC Id(以前在单独的CloudFormation脚本中创建)以便在VPC中创建子网?在创建子网时引用CloudFormation脚本中的现有AWS VPC Id
回答
引用它的名字 即。 "VpcId" : { "Ref" : "myVPC" },
在类似:
{
"Type" : "AWS::EC2::Subnet",
"Properties" : {
"AvailabilityZone" : String,
"CidrBlock" : String,
"Tags" : [ Resource Tag, ... ],
"VpcId" : { "Ref" : String }
}
}
文档这里: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-subnet.html
在模板定义VPC,包括在输出部分中的VPC ID:
"Outputs" : {
"VPC" : {
"Value" : {"Ref":"VPC"},
"Description" : "VPC ID"
},
...
}
在模板为使用VPC堆叠,为VPC ID定义参数:
"Parameters" : {
"VPC" : {
"Type" : "String",
},
...
}
创建此堆栈时,请在VPC定义堆栈上调用describe-stack
以从输出中获取ID,并将其作为参数VPC
传递给create-stack
。
基本上是正确的 - 但“类型”不能简单地为VPC字符串,它必须是“AWS :: EC2 :: VPC :: Id”,就像这里记录:http ://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html – jebbie 2017-06-07 22:02:52
字符串应该可以正常工作(或者至少在我编写此代码时),但使用更具体的类型更好。谢谢。 – bsvingen 2017-06-08 22:15:59
至少在我现在使用的最新awscli中,它将失败,在不使用此特定类型的模板上发生验证错误;) – jebbie 2017-06-12 17:25:14
或者从输入VPC的ID,如
"VpcId" : {
"Type" : "AWS::EC2::VPC::Id",
"Description" : "VpcId of your existing Virtual Private Cloud (VPC)",
"ConstraintDescription" : "must be the VPC Id of an existing Virtual Private Cloud."
},
- 1. 在CloudFormation中如何从选定的子网ID引用VPC ID?
- 2. AWS CloudFormation:子网具有不同的VPC Id
- 3. 请求AWS CloudFormation脚本中的现有子网组
- 4. Cloudformation脚本生成“没有找到默认VPC的子网”
- 5. vpc none不存在。 - AWS CloudFormation
- 6. 向ELB和子网添加子网Cloudformation Beanstalk脚本中的值
- 7. 如何在VPC上创建子网时确定AWS Cloudformation中的ipv6 CIDR块前缀
- 8. 如何在opscode主厨中创建AWS vpc,子网,安全组?
- 9. 由于子网无效导致无法在AWS中创建VPC
- 10. 使用Ansible在AWS中创建VPC
- 11. 如何使用aws java SDK从子网ID获取VPC ID?
- 12. AWS CloudFormation VPC和Subnet的问题
- 13. 在aws vpc中使用私有子网的原因是什么?
- 14. 创建Aws Cloudformation Ec2 t2.micro模板
- 15. 什么是VPC,AWS中的子网
- 16. AWS CloudFormation Internet网关出错
- 17. AWS CLI创建默认VPC
- 18. 有没有办法使用cloudformation或AWS CLI创建AWS Dashboard
- 19. 在特定的VPC上创建AWS RDS
- 20. 如何使用mySQLworkbench连接AWS私有子网中的RDS VPC
- 21. 如何确定AWS VPC子网是否为“公有子网”?
- 22. CloudFormation脚本 - 从AMI创建实例
- 23. 增加AWS VPC子网最大实例
- 24. AWS VPC子网划分方法
- 25. 更新现有的安全组创建新的EC2 CloudFormation
- 26. 使用terraform在非默认VPC中创建AWS RDS实例
- 27. AWS使用VPC和Autoscalled Windows实例的Cloudformation故障
- 28. AWS CloudFormation - 分享用户数据的脚本中使用跨EC2s
- 29. 使用AWS Cloudformation创建Elasticsearch服务:“创建Elasticsearch域未稳定”
- 30. AWS创建vpc并启动实例
它看起来像我需要有一个参数或映射,然后硬编码的VPC ID,然后在子网脚本,除非VPC引用它和子网全部使用相同的脚本创建,以便能够使用“VpcId”引用VPC ID:{“Ref”:“myVPC”}。 – Roobie 2014-11-04 22:12:43
如果你已经有一个VPC它将有一个Id只是把它放在参考。即“VpcId”:{“参考”:“vpc-123456”} – 2014-11-06 11:02:45
不起作用:模板验证错误:模板格式错误:未解决的资源依赖关系... – Ashesh 2015-09-04 17:40:06