question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

EC2 Copy Snapshot Ignoring Destination Region Parameter

See original GitHub issue

When I attempt to call copy_snapshot using the DestinationRegion parameter, it is ignored in favour of the region that the Lambda is run from.

For example, I wanted to copy a snapshot from us-east-1 to us-west-2, so I made this call similar to the one in the boto3 docs:

response = ec2.copy_snapshot(
    SourceSnapshotId='snapshotId',
    DestinationRegion='us-west-2',
    SourceRegion='us-east-1',
    Description = "TEST"
)

The response that I receive looks correct, however instead of the copy going to us-west-2, it winds up in the region from which I call the Lambda which is generally us-east-1.

When I make the call using the AWS CLI, I get the same result as I expect (copy goes to us-west-2), so I feel like this is an issue on boto’s end.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
FrancescoRizzicommented, Jan 27, 2017

I was going to point out the inconsistency in the boto3 documentation (DestinationRegion is described in the Parameters section, but not used in the Request Syntax section)… but now that I read this…

If I read correctly, you’re saying the ec2 client.copy_snapshot does not use the DestinationRegion at all, because it uses the “current” region (from the client’s session) as the destination. And, indeed, it requires the SourceRegion argument (feels like we could call this a “pull” model).

If I’m writing a script to run, for instance, on my machine, I can establish a session with the source region, look among the snapshots to find one I wish to copy (grab its id), then establish a separate/new session with the destination region, and use the ec2 client copy_snapshot to perform the copy. Feels a bit clunky, but …hmm… ok…

But if I am a Lambda? If I’m a Lambda running in the source region, then it’s easy to look at the snapshots available to find the one I want to copy, but then I have to make a separate session with the destination region, and use that client’s copy_snapshot method. Right?

'Cause if my Lambda was running in the destination region (in which case the client on which I call copy_snapshot can use the implicit current region), I don’t think I have a way to get the list of available snapshots from the source region (no filter in DescribeSnapshots talks about regions)… except by opening a separate session with the source region and using a client from that session …

It does feel clunky, doesn’t it?

3reactions
vineethvijaycommented, Apr 20, 2018

This is possible as @FrancescoRizzi suggested, lambda function can be run from 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)

Read more comments on GitHub >

github_iconTop Results From Across the Web

CopyDBSnapshot - Amazon Relational Database Service
Copies the specified DB snapshot. The source DB snapshot must be in the available state. You can copy a snapshot from one AWS...
Read more >
python - boto - copy snapshot to another region - Stack Overflow
You can use the copy_snapshot() method in the EC2 module to copy snapshots ... EC2 Copy Snapshot Ignoring Destination Region Parameter.
Read more >
copy-snapshot — AWS CLI 2.1.29 Command Reference
Copies a point-in-time snapshot of an EBS volume and stores it in Amazon S3. You can copy a snapshot within the same Region,...
Read more >
AWS EBS Ultimate Guide & 5 Bonus Features to Try
Move the snapshot with the command aws ec2 copy-snapshot. Provide the parameters --source-region, --source-snapshot-id, --destination-region (optional, but ...
Read more >
community.aws.ec2_snapshot_copy module – Copies an EC2 ...
Copies an EC2 Snapshot from a source region to a destination region. Requirements . The below requirements are needed on the host...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found