【发布时间】:2017-02-23 00:05:45
【问题描述】:
我想创建一个 python 脚本,我可以在其中传递参数/输入来指定实例类型,然后附加一个额外的 EBS(如果需要)。
ec2 = boto3.resource('ec2','us-east-1')
hddSize = input('Enter HDD Size if you want extra space ')
instType = input('Enter the instance type ')
def createInstance():
ec2.create_instances(
ImageId=AMI,
InstanceType = instType,
SubnetId='subnet-31d3ad3',
DisableApiTermination=True,
SecurityGroupIds=['sg-sa4q36fc'],
KeyName='key'
)
return instanceID; ## I know this does nothing
def createEBS():
ebsVol = ec2.Volume(
id = instanceID,
volume_type = 'gp2',
size = hddSize
)
现在,ec2.create_instances() 是否可以返回 ID 或者我是否必须重复保留?
还是我做一个 ec2.create(instance_id) / return instance_id?文档在这里不是特别清楚。
【问题讨论】:
-
create_instance将返回一个响应对象,这是您在创建后获取实例 ID 的地方。
标签: python amazon-ec2 boto boto3