python - Boto3/AWS:创建实例时“ImageId 不存在”
问题描述
我已经制作了 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)
推荐阅读
- excel - VBA 在数组中查找所有正则表达式匹配项
- jenkins - Jenkins CasC 处理令牌配置即代码
- python - 特金特。为什么我的“create_account()”函数不起作用?
- linux - 有人在 Pop_OS 20.04 上遇到过这个 Navicat 12 字体问题吗?
- python - 为什么运行这些代码后输出 (True, 3)?
- javascript - 我的快速服务器的代理服务器在我的 React 应用程序中不起作用
- javascript - 一次性变量:你能确保每个枚举成员只被引用一次吗?
- java - 使用resilience4j 实现节流/去抖动
- github - 我在 github push origin 中遇到错误
- sorting - 如何在我的应用程序的每个 p:selectOneMenu 中对 f:selectItems 进行排序?