我正在使用以下 Cloud Formation 模板创建一个 EC2 实例。 将此模板命名为“dinesh.json”。
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Dinesh template",
"Resources" : {
"MyEC2Instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"ImageId" : "ami-775e4f16",
"InstanceType" : "t2.micro",
"KeyName" : "****"
}
}
}
}
现在,使用 boto3 库,我将启动上述模板。
import boto3
cft = boto3.client('cloudformation')
create_cft = cft.create_stack(StackName="Dinesh",TemplateURL=r'https://s3-us-west-2.amazonaws.com/dsp-bucket/dinesh.json')
print create_cft
运行成功并得到如下输出:
{u'StackId': 'arn:aws:cloudformation:us-west-2:089691119308:stack/Dinesh/5b573240-548a-11e6-90a0-50a68a0bca36', 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '5b507be9-548a-11e6-8405-55192e2be20a', 'HTTPHeaders': {'x-amzn-requestid': '5b507be9-548a-11e6-8405-55192e2be20a', 'date': 'Thu, 28 Jul 2016 06:13:09 GMT', 'content-length': '376', 'content-type': 'text/xml'}}}
现在,我想获取上面创建的 EC2 实例的信息,如公共(public) IP、私有(private) IP 和其他信息。
那么,有人可以建议我如何检索此特定 EC2 实例的信息吗?
请告诉我除了 boto3 之外执行上述操作的各种方法。
最佳答案
使用 GetAtt 函数。例如,如果您创建了一个名为 bob 的 ec2,那么将其添加到您的输出部分将显示 privateip
"Outputs": {
"AddressOfbob": {
"Description": "Domainame",
"Value": {
"Fn::GetAtt": [
"bob",
"PrivateIp"
]
}
}
}
关于python-2.7 - 获取使用云形成模板创建的EC2实例信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38629099/