简体   繁体   中英

How/Can I set up an instance to use an already made for AWS ec2 using python 3

Is there a way of using a made key pair when creating a new instance using python 3. Can i just insert a new line into this code?

#!/usr/bin/env python3
import boto3
ec2 = boto3.resource('ec2')
instance = ec2.create_instances(
    ImageId='ami-0713f98de93617bb4',
    MinCount=1,
    MaxCount=1,
    InstanceType='t2.nano')
print (instance[0].id)

Specify a KeyName parameter like this:

instance = ec2.create_instances(
    ImageId='ami-0713f98de93617bb4',
    MinCount=1,
    MaxCount=1,
    InstanceType='t2.nano',
    KeyName='myKeyName')

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html#EC2.ServiceResource.create_instances

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM