Boto3/AWS: "ImageId doesn't exist" 创建实例时

Boto3/AWS: "ImageId doesn't exist" when creating Instance

我制作了一个 AMI 的副本,我正在尝试 运行 使用此代码:

import boto3

instance_id=("i-0e2bbdf4fc43bf6db")

client = boto3.client("ec2",region_name="us-west-2")
ec2 = boto3.resource("ec2")

ec2.create_instances(ImageId="ami-9d623ee5",MinCount=1,MaxCount=1)

返回 ClientError:

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

可能是什么问题? 谢谢!

假设AMI在同一个区域...

您的代码有误:更改为类似于以下内容:

import boto3

instance_id=("i-0e2bbdf4fc43bf6db")

session = boto3.Session("ec2",region_name="us-west-2")
ec2 = session.resource("ec2")

OR

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

ec2.create_instances(ImageId="ami-9d623ee5",MinCount=1,MaxCount=1)