aws-sdk-ruby
aws-sdk-ruby copied to clipboard
Region detection
Is there currently a way too detect the current region like is available in the Java SDK for example https://aws.amazon.com/blogs/developer/determining-an-applications-current-region/
At the moment I am having to set the AWS_REGION environment variable manually which I was hoping to avoid.
We haven't implemented region fetching from the EC2 instance metadata service yet, no. Adding this as a feature request.
Thanks @awood45!
+1
Adding to feature request backlog.
Reopening - deprecating usage of Feature Requests backlog markdown file.
@mullermp Currently when I pull a single EC2 instance metadata, it has given instance data and it's availability zone information but no region information included in the response. Can we considered availability zone as current region information?
Hi @sivagollapalli -- If I recall correctly, this was put aside because there were changes coming to the IMDS API and we didn't want to include any potential breakage from before and after that change. I can check back in with the EC2 team after the holidays and see if that's still the case. Last I looked, I believe there is a region field or some way to get the region (using the AZ as you said).
@mullermp Any update on this?
Right now there's no good way to get the region
docs: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-categories.html
Unfortunately this has been long requested, I will try to make a stink on it somewhere: https://forums.aws.amazon.com/thread.jspa?threadID=77228
The best thing we can do is query for placement/availability-zone
and strip off the last letter, though this isn't guaranteed to work.
added PR @mullermp
placement/region
has been available for a while now - reminder to myself that I will pick this up as part of https://github.com/aws/aws-sdk-ruby/issues/2444
Greetings! We’re closing this issue because it has been open a long time and hasn’t been updated in a while and may not be getting the attention it deserves. We encourage you to check if this is still an issue in the latest release and if you find that this is still a problem, please feel free to comment or open a new issue.
looks like there's already code to query the metadata service for the region - https://github.com/aws/aws-sdk-ruby/blob/version-3/gems/aws-sdk-core/lib/aws-defaults/defaults_mode_config_resolver.rb#L65-L86
Setting AWS_DEFAULTS_MODE=auto
does not seem to set the region. Any chance this can be updated?
The defaults mode is cross SDK behavior and the application region detection is used to determine only whether to use in-region or cross-region defaults (mostly http timeout defaults) and wasn't intended to be used to set client region.
But that being said - providing region detection as part of client region resolution is still a feature request we are planning on.
Doing so in the current major version I think is risky and can cause errors (changes configuration in a minor version). If you agree, I think we should label this as major version only.
The precedence is already environment then profile. I don't see how having the metadata service be the lowest priority (and match how credentials are resolved) is a breaking change. especially since it's how it works in both v1 and v2
Since region
is a required configuration option and precedence is already environment, then profile, I do agree, I think the risk is lower. I am slightly concerned by an increase in client creation time (caused by the extra network call) + an extra network call. But this would only happen in the case where client creation would currently fail and raise an error.
Ah yeah that makes sense, if it's last. We have very aggressive timeouts for "testing" if we are on an ec2 host. I suppose we only have to do that once in both the region config chain (new concept) and credential provider chain if we use some client class variable or something like that.