在我在aws ec2上使用的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"
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
省略了很多,但这就是与添加 ip 相关的所有内容。
我的问题是,文档说只有 DeviceIndex 为 eth0 的网络接口才能拥有公共 IP 地址,但使用 eth0 会导致错误:
Encountered non numeric value for property DeviceIndex
Run Code Online (Sandbox Code Playgroud)
但是如果我将设备 ID 设置为 0 我会得到
The associatePublicIPAddress parameter …
Run Code Online (Sandbox Code Playgroud)