在我在aws 2‘S上使用的vpc中,默认情况下不会获得公共ip地址。在引用这和这文档之后,我尝试手动添加一个。
目前,我的cloudformation模板包括
"netinterface" : {
"Type" : "AWS::EC2::NetworkInterface",
"Properties" : {
"SubnetId" : {"Ref": "Subnet"}
}
},
"billingattributionapi" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"NetworkInterfaces" : [
{
"AssociatePublicIpAddress" : "true",
"DeviceIndex" : "eth0",
"NetworkInterfaceId" : {"Ref" : "netinterface"},
"DeleteOnTermination" : "true"
}
]
}
}
有很多省略,但这是与添加ip相关的一切。
我的问题是,文档中说只有具有DeviceIndex of eth0的网络接口才能有公共ip地址,但是使用eth0会导致错误。
Encountered non numeric value for property DeviceIndex
但是,如果我将设备id设置为0,我将得到
The associatePublicIPAddress parameter cannot be specified for a network interface with an ID
但是,如果我删除NetworkInterfaceId并按照文档的要求添加子网id,我将得到
Network interfaces and an instance-level subnet ID may not be specified on the same request
在这一点上,我不知道该怎么办。根据文档,我最初的方法似乎是正确的。以前有人这样做过,能指出我做错了什么吗?
发布于 2014-11-22 19:35:19
这就是对我有用的东西:
在"AWS::EC2::Instance“资源中将私有IP设置为主IP地址:
"NetworkInterfaces" : [
{
"DeleteOnTermination" : true,
"Description" : "Main interface",
"DeviceIndex" : "0",
"PrivateIpAddresses" : [
{
"PrivateIpAddress" : {
"Ref" : "InternalIPAddress"
},
"Primary" : true
}
],
"GroupSet" : [
{
"Ref" : "SecurityGroupId"
}
],
"SubnetId" : {
"Ref" : "VPCSubnet"
}
}
],
请注意,上面对"InternalIPAddress“的引用是一个参数,用于传递计算机应有的内部IP。我不认为这是必要的,因为没有它,实例将通过dhcp获取一个IP。
然后在模板后面添加一个类型为“AWS::EC2::EIP”的资源:
"EIPExternalIP" : {
"Type" : "AWS::EC2::EIP",
"Properties" : {
"InstanceId" : {
"Ref" : "Instance"
},
"Domain" : "vpc"
}
},
可以使用{"Ref“:"EIPExternalIP"}获取外部IP。
https://serverfault.com/questions/645954
复制相似问题