如何解决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']
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。