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

S3 crt client doesn't pick up the default region

Open dhananjays opened this issue 4 years ago • 3 comments

Confirm by changing [ ] to [x] below to ensure that it's a bug:

Describe the bug S3-crt client doesn't automatically get the region unlike the S3 client which automatically fetches region (using the chain of AWS_DEFAULT_REGION -> profile -> instance metadata). The user is forced to provide the correct region when creating the s3-crt client

SDK version number 1.9

Platform/OS/Hardware/Device EC2 Linux instance

To Reproduce (observed behavior) Steps to reproduce the behavior (please share code) Create S3 client without setting region in the client config. It automatically picks up the default region from the profile/instance metadata (This is as expected from version 1.8 as mentioned here - https://aws.amazon.com/blogs/developer/aws-sdk-for-c-version-1-8-developer-preview/)

Create S3-crt client without setting region in the client config. It does not pick the default region as expected.

Expected behavior S3-crt client should automatically pick up the default region as done by the S3 client

dhananjays avatar Sep 09 '21 06:09 dhananjays

Hi @dhananjays , So, it seems like you've figured out the workaround , but for the record this behavior is not expected of the s3-crt default constructor.

The s3-crt default provider chain is reduced to make it faster to go through, and it will only check for the region in the AWS_DEFAULT_REGION environment variable, a specified profile in the config file or the one hard coded on the Aws::S3Crt::ClientConfiguration object. Having said that, this could be a feature request, but I can't make any promises on when we could work on it.

KaibaLopez avatar Sep 09 '21 22:09 KaibaLopez

Here is how we back-ported that in our code, since we ran into the same issue: the CRT does not pickup AWS_{,DEFAULT_}REGION:

        Aws::S3Crt::ClientConfiguration config;
        // ...
        config.region = []() -> Aws::String {
            // Return the configured AWS region, using us-east-1 as fallback. This is normally part
            // of Aws::Client::ClientConfiguration, but is not implemented for the S3CrtClient.
            Aws::String region = os::getenv("AWS_DEFAULT_REGION");
            if (!region.empty()) {
                return region;
            }

            region = os::getenv("AWS_REGION");
            if (!region.empty()) {
                return region;
            }

            // The profile may also contain a region value.
            if (Aws::Config::HasCachedCredentialsProfile("default")) {
                region = Aws::Config::GetCachedCredentialsProfile("default").GetRegion();
                if (!region.empty()) {
                    return region;
                }
            }
            return Aws::Region::US_EAST_1;
        }();

grrtrr avatar Mar 19 '22 15:03 grrtrr

The problem is also resolved by #1884.

grrtrr avatar Mar 19 '22 20:03 grrtrr

Merged: https://github.com/aws/aws-sdk-cpp/pull/2098

jmklix avatar May 03 '24 17:05 jmklix

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.

github-actions[bot] avatar May 03 '24 17:05 github-actions[bot]

Thank you.

grrtrr avatar May 03 '24 18:05 grrtrr