python - Moto 警告:使用 ec2_backend.describe_images() 为您的测试找到合适的图像
问题描述
我正在尝试测试一个使用 boto3 中的 create_stack() 上传云形成的函数。
对于测试,我使用的是框架 moto。
对于测试,我使用 pytest 夹具在 yaml 中创建了一个 template_data:
@pytest.fixture(scope='function')
def template_body_data():
'The Cloud Formation template'
template_data = {
'Resources': {
'MyInstance': {
'Type': 'AWS::EC2::Instance',
'Properties': {'ImageId': 'ami-a4c7edb2', 'InstanceType': 't2.micro'},
}
}
}
return template_data
我所有的测试都有效。
问题是我收到此警告:
/home/myprofile/.cache/pypoetry/virtualenvs/cl-uploader-12nYBdPj-py3.8/lib/python3.8/site-packages/moto/ec2/models.py:517: PendingDeprecationWarning: Could not find AMI with image-id:ami-a4c7edb2, in the near future this will cause an error.
Use ec2_backend.describe_images() to find suitable image for your test
我怎样才能解决这个问题?
解决方案
使用下面第三步中的图像 ID,它将解决警告
client = boto3.client('ec2', aws_region)
image_response = client.describe_images()
image_id = image_response['Images'][0]['ImageId']
推荐阅读
- sql - sql server 选择组的第一行
- angular - 如何从浏览器访问网络选项卡中的请求标头部分
- ansible - 有没有办法将完整的 Ansible 剧本(而不仅仅是任务)委托给另一个主机?
- javascript - 通过对象属性实现条件逻辑
- javascript - 如何在 ag-grid 的事件方法中使用 javascript 默认事件对象
- ionic3 - 离子原生照片查看器无法在离子 3 中加载图像
- php - 如何从 cakePHP 中的连接表中获取数据不可用的表中的数据
- php - 在不查询数据库的情况下使用 SSE 和 Laravel
- linux - dockerfile 中的 RUN 命令产生的结果与在容器内手动运行相同的命令不同
- mysql - 将变量名作为表名时出错