Question

Any ideas on how to easily copy a snapshot to another region with boto?

You can easily do it through the management console - right clicking the snapshot, then "copy", then choosing your preferable region.

I hoped to have something similar with boto but couldn't find any.

Thanks

Était-ce utile?

La solution

You can use the copy_snapshot() method in the EC2 module to copy snapshots within a region or between regions. For example, if you had an existing snapshot in us-east-1 and you wanted to copy it to us-west-2 you could do this:

import boto.ec2

conn = boto.ec2.connect_to_region('us-west-2')
conn.copy_snapshot(source_region='us-east-1', source_snap_id='snap-12345678',
                   description='My new copy')

see: boto.ec2.connection.EC2Connection.copy_snapshot

Autres conseils

Faced a bug with boto3, as the destination region parameter gets skipped and it copies snapshots to same region itself.

EC2 Copy Snapshot Ignoring Destination Region Parameter

For this to work, lambda function can be created in destination region, but set the region parameter in the code to the source region where you have the snasphots.

region = 'eu-central-1'
ec = boto3.client('ec2',region_name=region)

def lambda_handler(event, context):
    response=ec.copy_snapshot(SourceSnapshotId='snap-082*********4aac2',
                     SourceRegion=region,
                     DestinationRegion='eu-west-1',
                     Description='copied from Frankfurt')
    print (response)

Here, the lambda function is created in eu-west-1(Ireland), and SourceSnapshotId is a snap Id from eu-central-1(Frankfurt)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top