aws-sdk-cpp
aws-sdk-cpp copied to clipboard
S3 crt client doesn't pick up the default region
Confirm by changing [ ] to [x] below to ensure that it's a bug:
- [ x] I've gone though Developer Guide and API reference
- [ x] I've searched for previous similar issues and didn't find any solution
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
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.
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;
}();
The problem is also resolved by #1884.
Merged: https://github.com/aws/aws-sdk-cpp/pull/2098
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.
Thank you.