代码之家  ›  专栏  ›  技术社区  ›  Yaroslav Bulatov

使用boto3将AMI复制到另一个区域

  •  0
  • Yaroslav Bulatov  · 技术社区  · 6 年前

    我正在尝试自动化我在AWS EC2控制台上的“Copy AMI”功能,有人能告诉我一些通过boto3实现这一点的Python代码吗?

    2 回复  |  直到 6 年前
        1
  •  3
  •   John Rotenstein    6 年前

    EC2 — Boto 3 documentation :

    response = client.copy_image(
        ClientToken='string',
        Description='string',
        Encrypted=True|False,
        KmsKeyId='string',
        Name='string',
        SourceImageId='string',
        SourceRegion='string',
        DryRun=True|False
    )
    

    确保将请求发送到 目的地 ,传入对 SourceRegion .

        2
  •  1
  •   RaghuCK    6 年前

    更准确地说。

    假设你要复制的AMI在 美国东部-1 (源区域)。 你的要求是把这个复制到 美国西部-2 (目的地)

    将boto3 EC2客户端会话转到us-west-2区域,然后在源区域中传递us-east-1。

    import boto3
    session1 = boto3.client('ec2',region_name='us-west-2')
    
    response = session1.copy_image(
       Name='DevEnv_Linux',
       Description='Copied this AMI from region us-east-1',
       SourceImageId='ami-02a6ufwod1f27e11',
       SourceRegion='us-east-1'
    )
    
    推荐文章