使用boto3无法创建EC2实例

3

我无法使用boto3创建EC2实例。

我正在尝试使用boto3创建一个实例。

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

我的区域是美国东部(俄亥俄州)

我不确定如何找到特定区域的AMI。我只是选择了可用的内容。

错误信息为:

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

我从enter image description here中复制了AMI ID。
1个回答

3
我觉得您缺少了region_name参数。
您可以在代码中设置region_name参数,如下所示:
ec2 = boto3.resource('ec2', region_name='us-east-2')

希望能帮到你。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接