相关文章推荐
喝醉的电脑桌  ·  sprintf unsigned int ...·  5 月前    · 
无聊的杨桃  ·  python+requests+excel+ ...·  7 月前    · 
想表白的仙人掌  ·  android ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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.

Note that a Windows file has the different End of line character CRLF which can causes errors in Linux.

Apparently the AWS SDK thinks your region is us-west-2. Instead of copying the .aws directory from your windows PC, setup the AWS configuration in your linux box from scratch.

  • Delete or backup .aws directory and make sure there is no ~/.aws.
  • Run 'aws configure'
  • $ aws configure
    AWS Access Key ID [None]: <YOUR AWS ID>
    AWS Secret Access Key [None]: <YOUR KEY>
    Default region name [None]: us-east-1      <----- Region
    Default output format [None]: json         <----- change to the format you prefer
    

    Please spend enough time to go through Configuring the AWS CLI. Without understanding the basics and how the AWS configuration work, you will spend so much time without solving the issue.

    Then test your S3 bucket from the linux box with the AWS CLI s3 commands, such as listing files in the S3 bucket If s3 commands do not work, no chance your Java program works.

  • Using Amazon S3 with the AWS CLI
  • Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.