【问题标题】:How to create ami with specific image-id using moto?如何使用 moto 创建具有特定图像 ID 的 ami?
【发布时间】:2018-12-11 03:27:12
【问题描述】:

我正在使用 moto 为我的应用程序模拟 aws。我想知道是否可以在具有特定图像 ID 的 moto 中创建 ami(例如:ami-1a2b3c4d)。 谢谢!

【问题讨论】:

    标签: amazon-web-services mocking moto


    【解决方案1】:

    这是一个直接来自文档的示例:

    from . import add_servers
    from moto import mock_ec2
    
    @mock_ec2
    def test_add_servers():
        add_servers('ami-XXXXXXX', 2)
    
        client = boto3.client('ec2', region_name='us-west-1')
        instances = client.describe_instances()['Reservations'][0]['Instances']
        assert len(instances) == 2
        instance1 = instances[0]
        assert instance1['ImageId'] == 'ami-XXXXXXXX'
    

    您可以选择任何您想要的 AMI ID,没有任何限制。我不确定我是否理解问题所在,因为这些是“模拟”资源,因此它们可以采用任何格式/包含您想要的任何名称。

    【讨论】:

    • python3.7/site-packages/moto/ec2/models.py:495: PendingDeprecationWarning: Could not find AMI with image-id:ami-fake, 在不久的将来这会导致错误.
    猜你喜欢
    • 1970-01-01
    • 2011-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多