Using aws-sdk-cpp, I created AWS client to access S3 bucket. It works with Standard AWS Regions, but not AWS GovCloud (US). Note that we only pass bucket name and region (us-gov-west-1) to SDK, without specifying any endpoint. How can we make SDK use correct endpoint for regions associated with AWS GovCloud?
Thanks a lot!
Aws::Client::ClientConfiguration config = get_client_config(input_cfg);
// get_client_config() sets proxy, region , timeout, caFile , useDualStack , etc
bool useVirtualAddressing = true;
Aws::Auth::AWSCredentials credentials;
//credentials is set
aws::S3::S3Client s3Client(credentials, config, Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy::Never, useVirtualAddressing);
List objects:
Aws::S3::Model::ListObjectsV2Request requestV2;
requestV2.WithBucket(bucketName);
requestV2.WithPrefix(prefix1);
requestV2.SetDelimiter("/");
auto acctOutcome = s3Client.ListObjectsV2(requestV2);
...
Get object:
Aws::S3::Model::GetObjectRequest object_request;
object_request.SetBucket(bucketName);
object_request.SetKey(objectKey);
const char *base_fn = strrchr(objectKey, '/') + 1;
Aws::S3::Model::GetObjectOutcome objectOutcome =
s3Client.GetObject(object_request);
...
For the bucket and region in AWS GovCloud, SDK threw error saying can't connect to server. We expect SDK automatically detect the region is in AWS GovCloud and select the correct endpoint.