aws boto - how to create instance and return instance_id
<p>I want to create a python script where I can pass arguments/inputs to specify instance type and later attach an extra EBS (if needed).</p>

<pre><code>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
        )
</code></pre>

<p>Now, can ec2.create_instances() return ID or do I have to do an iteration of reservations?</p>

<p>or do I do an ec2.create(instance_id) / return instance_id? The documentation isn't specifically clear here.</p>

<p>The docs state that the call to create_instances()</p>

<p><a href="https://boto3.readthedocs.io/en/latest/reference/services/ec2.html#EC2.ServiceResource.create_instances" rel="nofollow">https://boto3.readthedocs.io/en/latest/reference/services/ec2.html#EC2.ServiceResource.create_instances</a></p>

<p>Returns list(ec2.Instance). So you should be able to get the instance ID(s)  from the 'id' property of the object(s) in the list.</p>

python amazon-ec2 boto boto3