简体   繁体   中英

Unable to create an ec2 instance using boto3

I am not able to create an EC2 instance using boto3.

I am trying to create an instance using boto3.

ec2 = boto3.resource('ec2')
ec2.create_instances(ImageId='ami-0d8f6eb4f641ef691', MinCount=1, MaxCount=1, InstanceType='t2.micro')

My region is US East(Ohio)

I am not sure how to find the AMI to a specific region. I just selected what was available.

The error message is

botocore.exceptions.ClientError: An error occurred (InvalidAMIID.NotFound) when calling the RunInstances operation: The image id '[ami-0d8f6eb4f641ef691]' does not exist

and I copied the AMI ID from the:

在此处输入图片说明

I think you are missing the region_name parameter.

You can set the region_name is your code as:

ec2 = boto3.resource('ec2', region_name='us-east-2')

Hope it helps.

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