Found a few topics that covered the same error in Stackoverlfow, but the scenarios don't match mine. Have an AWS s3 java client program that runs fine on windows in uploading files to an s3 bucket. Now trying to run the same program on a Linux (Ubuntu) server, and getting this error
com.amazonaws.services.s3.model.AmazonS3Exception: The authorization header is malformed; the region 'us-east-1' is wrong; expecting 'eu-west-2' (Service: Amazon S3; Status Code: 400; Error Code: AuthorizationHeaderMalformed; Request ID:
I uploaded the .aws\credentials file from my Windows laptop to the ~/.aws/ directory on the server. Didn't make any changes. I confirmed I had the right credential key after cross-checking with IAM on AWS.
Here's the code (yes, it's hardcoded) that sets the region AmazonS3 s3Client; private static final byte[] BUFFER = new byte[4096 * 1024];
public FileUpload() {
s3Client = AmazonS3ClientBuilder.standard().withRegion("us-east-1").build();
}
I created the bucket manually in the AWS console and it's in the us-east-1 region.
Do I need a config file under ~/.aws ? Don't have one on the Windows laptop
I think it's one of those dumb things with AWS where it's giving a somewhat misleading error. When I created the bucket name in the AWS console, there was no error that the bucket name already existed in another region, so I assumed all was good. So just now I deleted the bucket and created a new one and used part of my account name in the bucket name to make sure it's unique across regions. This time the upload from the Linux system worked. So ended up not having to redo anything with the configuration on the Linux server.