Skip to content

Instantly share code, notes, and snippets.

@ryansch
Created June 20, 2016 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryansch/c6782325f19af326cc379450792307f2 to your computer and use it in GitHub Desktop.
Save ryansch/c6782325f19af326cc379450792307f2 to your computer and use it in GitHub Desktop.
Get current AWS region
def current_region
return @current_region if @current_region != nil
response = Excon.get(
'http://169.254.169.254/latest/meta-data/placement/availability-zone',
expects: [200],
connect_timeout: 2,
read_timeout: 2,
write_timeout: 2,
tcp_nodelay: true
)
# chop removes the AZ letter from the end giving us the region
@current_region = response.body.chop
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment