Moto警告:使用ec2_backend.describe_images()查找适合您的测试的图像

时间:2020-08-13 13:23:15

标签: python python-3.x pytest boto3 moto

我正在尝试测试一个功能,该功能使用来自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

我该如何解决?

1 个答案:

答案 0 :(得分:1)

使用下面第三步中的图像ID,它将解决警告

client = boto3.client('ec2', aws_region)
image_response = client.describe_images()
image_id = image_response['Images'][0]['ImageId']
相关问题