Moto警告:使用ec2_后端。描述_images()为您的测试找到合适的映像

2024-06-01 00:22:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图测试一个函数,该函数使用boto3中的create_stack()上传云结构

对于测试,我使用的是框架moto

对于测试,我使用pytest夹具在yaml中创建一个模板_数据:

@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

我怎样才能解决这个问题


Tags: 函数image框架datapyteststackcreatetemplate
1条回答
网友
1楼 · 发布于 2024-06-01 00:22:58

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

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

相关问题 更多 >