Question

I have migrated (actually copied) a Debian Amazon EC2 server from North Virginia to the Ireland datacentre, within a VPC.

I have been using this python script to make automated EBS snapshot backups very night, but since I have migrated the server, it doesn't work.

The new volume is not recognised as existing, but it can make a snapshot of the old volume in North Virginia, even though the server is in Ireland.

I get this error:

root@ip-10-0-0-100:~# python /srv/bin/manage_snapshots.py vol-fac935ae 14 "Test Backup"
Traceback (most recent call last):
  File "/srv/bin/manage_snapshots.py", line 36, in <module>
    volumes = conn.get_all_volumes([vol_id])
  File "/usr/local/lib/python2.7/dist-packages/boto/ec2/connection.py", line 2099, in get_all_volumes
    [('item', Volume)], verb='POST')
  File "/usr/local/lib/python2.7/dist-packages/boto/connection.py", line 1131, in get_list
    raise self.ResponseError(response.status, response.reason, body)
boto.exception.EC2ResponseError: EC2ResponseError: 400 Bad Request
<?xml version="1.0" encoding="UTF-8"?>
<Response><Errors><Error><Code>InvalidVolume.NotFound</Code><Message>The volume 'vol-fac935ae' does not exist.</Message></Error></Errors><RequestID>30ba36b6-2f07-4c5f-b307-36865cb7ef44</RequestID></Response>

Assuming the problem is in boto configuration, how can I tell it that the server is now in Ireland?

I already have this in ~/.profile:

# set AWS region
export EC2_URL=https://ec2.eu-west-1.amazonaws.com

But I think that is only for the command line ec2-api-tools.

Was it helpful?

Solution 2

Boto is using us-east-1 region by default, that't why it was working fine until the migration.

For any other region, you have to update your boto.config file to explicitly set the region.

[Boto]
ec2_version = 2012-12-01
ec2_region_name = eu-west-1
ec2_region_endpoint = ec2.eu-west-1.amazonaws.com

Location for boto.config:

/etc/boto.cfg - for site-wide settings that all users on this machine will use
~/.boto - for user-specific settings

Manual: Boto Config

OTHER TIPS

You can find out which region an EC2 instance is in programmatically like this:

import boto.utils
data = boto.utils.get_instance_identity()
region_name = data['document']['region']

Once you know the region, you can connect to the correct region in your script like this:

import boto.ec2
conn = boto.ec2.connect_to_region(region_name)

This should allow your script to be able to run on any instance in any region.

This can also be done with the following Python code:

import boto.utils
m = boto.utils.get_instance_metadata()
print m['placement']['availability-zone']

Prints ap-southeast-2b in my case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top