Cloudformation:如何从实例获取SecondaryPrivateIP

时间:2015-12-23 10:17:24

标签: amazon-web-services amazon-ec2 amazon-cloudformation

在以下模板中,任何人都可以帮助我如何在不创建外部网络接口的情况下从实例中找到SecondryPrivateIP。

"radmachine": {
  "Type": "AWS::EC2::Instance",
  "Properties": {
    "ImageId": "ami-abcde123",
    "InstanceType": "t2.micro",
    "KeyName": "radkey",
    "DisableApiTermination": "false",
    "NetworkInterfaces": [{
        "AssociatePublicIpAddress": "false",
        "DeviceIndex": "0",
        "DeleteOnTermination": "true",
        "SubnetId": "123456",
        "GroupSet": "sg-56789",
        "SecondaryPrivateIpAddressCount": "1"
    }],
    "BlockDeviceMappings": [{"DeviceName": "/dev/xvda","Ebs": {"VolumeType": "gp2","DeleteOnTermination": "false","VolumeSize": "8"}}],
  }
}

提前致谢。

1 个答案:

答案 0 :(得分:0)

通读:
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-network-interface.html http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/MultipleIP.html http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html#AvailableIpPerENI

在了解了它应该如何工作后,请看:
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html

你对以下内容感兴趣: AWS :: EC2 :: NetworkInterface - >的 SecondaryPrivateIpAddresses

所以基本上你要求额外的辅助私有ips绑定到网络接口,然后使用Fn :: GetAtt来检索在构建时给予机器/接口的值。