'There are multiple potential sources for the new region to redirect to,
but they aren\'t all universally available for use. This will try to
find region from response elements, but will fall back to calling
HEAD on the bucket if all else fails.
:param bucket: The bucket to find the region for. This is necessary if
the region is not available in the error response.
:param response: A response representing a service request that failed
due to incorrect region configuration.'

def get_bucket_region(self, bucket, response):

    service_response = response[1]
    response_headers = service_response['ResponseMetadata']['HTTPHeaders']
    if ('x-amz-bucket-region' in response_headers):
        return response_headers['x-amz-bucket-region']
    region = service_response.get('Error', {}).get('Region', None)
    if (region is not None):
        return region
    try:
        response = self._client.head_bucket(Bucket=bucket)
        headers = response['ResponseMetadata']['HTTPHeaders']
    except ClientError as e:
        headers = e.response['ResponseMetadata']['HTTPHeaders']
    region = headers.get('x-amz-bucket-region', None)
    return region
