aws-sdk-ruby icon indicating copy to clipboard operation
aws-sdk-ruby copied to clipboard

Region detection

Open stefansedich opened this issue 7 years ago • 18 comments

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.

stefansedich avatar Mar 15 '17 19:03 stefansedich

We haven't implemented region fetching from the EC2 instance metadata service yet, no. Adding this as a feature request.

awood45 avatar Mar 15 '17 21:03 awood45

Thanks @awood45!

stefansedich avatar Mar 15 '17 21:03 stefansedich

+1

AlexMorreale avatar Mar 16 '17 00:03 AlexMorreale

Adding to feature request backlog.

awood45 avatar Apr 21 '17 17:04 awood45

Reopening - deprecating usage of Feature Requests backlog markdown file.

mullermp avatar Oct 21 '19 22:10 mullermp

@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?

sivagollapalli avatar Dec 23 '19 13:12 sivagollapalli

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 avatar Dec 23 '19 18:12 mullermp

@mullermp Any update on this?

sivagollapalli avatar Jan 08 '20 13:01 sivagollapalli

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.

mullermp avatar Feb 28 '20 23:02 mullermp

added PR @mullermp

siva-wal avatar Apr 21 '20 15:04 siva-wal

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

mullermp avatar Dec 11 '20 01:12 mullermp

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.

github-actions[bot] avatar Dec 12 '21 00:12 github-actions[bot]

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?

makrsmark avatar Mar 01 '23 16:03 makrsmark

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.

alextwoods avatar Mar 01 '23 18:03 alextwoods

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.

mullermp avatar Mar 01 '23 22:03 mullermp

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

makrsmark avatar Mar 01 '23 22:03 makrsmark

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.

alextwoods avatar Mar 01 '23 22:03 alextwoods

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.

mullermp avatar Mar 02 '23 14:03 mullermp