Skip to content

Instantly share code, notes, and snippets.

@mmasashi
Created July 30, 2015 19:15
Show Gist options
  • Save mmasashi/1290830b7dde2530677c to your computer and use it in GitHub Desktop.
Save mmasashi/1290830b7dde2530677c to your computer and use it in GitHub Desktop.
convert s3 endpoint to region
# Convert s3-endpoint to region name
# http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
def self.endpoint_to_region(endpoint)
case endpoint.to_s
when ''
nil
when 's3.amazonaws.com', 's3-external-1.amazonaws.com'
'us-east-1'
when 's3-us-west-2.amazonaws.com'
'us-west-2'
when 's3-us-west-1.amazonaws.com'
'us-west-1'
when 's3-eu-west-1.amazonaws.com'
'eu-west-1'
when 's3.eu-central-1.amazonaws.com', 's3-eu-central-1.amazonaws.com'
'eu-central-1'
when 's3-ap-southeast-1.amazonaws.com'
'ap-southeast-1'
when 's3-ap-southeast-2.amazonaws.com'
'ap-southeast-2'
when 's3-ap-northeast-1.amazonaws.com'
'ap-northeast-1'
when 's3-sa-east-1.amazonaws.com'
'sa-east-1'
else
raise "Unsupported s3-endpoint:#{endpoint}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment