1
votes

I am testing AWS C++ SDK. I have set my region (eu-central-1) as a environment variable and in ~/.aws/config like it is said here : http://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/setup-credentials.html

I am testing this example code provided by AWS : https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/cpp/example_code/s3/put_object.cpp

The problem is that I receive this error : ExceptionName: AuthorizationHeaderMalformed Message: The authorization header is malformed; the region 'us-east-1' is wrong; expecting 'eu-central-1'

Why it doesn't use the region eu-central-1 ?

2
Suspect the AWS SDK for C++ does not use the ~/.aws/config file or environment variables. See docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/….jarmod

2 Answers

2
votes

The SDK does use the config file, however it does not automatically set region for you. The default region is us-east-1. Since, I'm assuming your bucket is in eu-central-1, you need to set the region on your ClientConfiguration to eu-central-1.

If you want to use the region from your config file, you can use this as a helper: https://github.com/aws/aws-sdk-cpp/blob/master/aws-cpp-sdk-core/include/aws/core/config/AWSProfileConfigLoader.h

2
votes

I came across the same issue, my awscli has verified that my default region is set to "us-west-2", but the SDK still picks up "us-east-1" as default region while ignoring the default set in ~/.aws/config file.

As a workaround, I used ClientConfiguration to setup the region before the EC2 client service call, snippet of code is shown below:

    Aws::Client::ClientConfiguration clientConfig;
    clientConfig.region = "us-west-2";
    Aws::EC2::EC2Client ec2(clientConfig);