The authorization header is malformed; the region 'us-east-1' is wrong; expecting 'eu-central-1'
Asked Answered
M

4

14

using Node.JS with the following config file

{ "accessKeyId" :"XXX", "secretAccessKey" :"XXXX", "region": "eu-central-1", "signatureVersion": "v4" }

I still receive this error message as if the aws sdk tries to access a us-east-1 region .

Any idea ?

Muley answered 6/12, 2017 at 6:52 Comment(5)
Maybe show a bit more code, for context?Period
@Michael-sqlbot , here is the node.js relevant code: s3bucketws.createBucket(function() { var data = {Bucket:S3_BASE_WS,Key: req.query.file, Body: body, ACL: 'public-read',ContentType: fileType,CacheControl:'public, max-age=2592000', Metadata: {timestamp:file_timestamp+''} }; s3bucketws.putObject(data, function(err) { if (err) { res.json({statusOK: false, description: err.message}); } else { }Muley
and here is the declaration : var s3bucketws = new AWS.S3({endpoint: 's3-eu-central-1.amazonaws.com' ,signatureVersion: 'v4', region: 'eu-central-1'});Muley
Try removing the endpoint declaration.Period
nope , removing endpoint declaration did not work . also AWS.config.update({region: 'eu-central-1'}); didn't work out , still get the : The authorization header is malformed; the region 'us-east-1' is wrong; expecting 'eu-central-1 erorMuley
M
35

According to AWS, there are three situations this can happen.

  1. When you are creating a bucket with a name that this already being used as a bucket name in your AWS account or in any other AWS account (Please note that S3 bucket names are globally unique).

  2. When you are doing an operation on your S3 bucket and you have set the Region variable (either when configuring the SDK or while using environment variables etc) to a region other than the one in which the bucket is actually present.

  3. You have recently deleted a S3 bucket in a particular region (say us-east-1) and you are trying to create a bucket (with the same name as the the bucket that was deleted) in another region right after deleting the bucket.

For point 3, give it up to two days and retry.

if a bucket which is present in a certain region say (us-east-1) is deleted, you can always create a bucket with the same name in another region. There is no such restriction in S3 that states you cannot do this. However, you will be able to do this only after you allow some time after deleting the bucket. This is because S3 buckets follow the Eventual Consistency model in the case of DELETE operation.

It means that after you delete a bucket, it takes a few hours, generally up-to 24 to 48 hours for the DELETE operation to be replicated across all our data centres. Once this change has propagated you can go ahead and create the bucket again in the desired region.

Mealie answered 17/4, 2020 at 1:14 Comment(4)
I ran into the same creating a S3 bucket with Terraform - the error message is ambiguous and makes it difficult to pinpoint the problem. The issue turned out to be a duplicate bucket name (per @mon's response). Instead of trying to think up a globally unique name, you could try using the "bucket_prefix" option (if you are using Terraform of course). This will create a unique bucket name beginning with the specified prefix.Afire
This happened to me because I gave a name of a bucket already in use.Fai
this only happens when bucket is created in region A, dropped and re-created in region B, and then dropped and attempted to be re-created in region A again. I could remove and re-create the bucket with the same name hundreds of times within the same region without any delays almost instantly. And I could also remove it in A, then re-create and remove in B, then in C, then in D, etc. almost instantly. Not sure how eventual consistency explains all thisBooklet
and in my case of A->B->A situation, it took around 1 hourBooklet
J
5

I ran into the same issue on 2023.

This tutorial helped me. It basically says that the bucket name need to be unique accross the whole region with all of the AWS accounts there are, so by changing my bucket name the issue was solved.

https://spacelift.io/blog/terraform-aws-provider

Juttajutty answered 9/8, 2023 at 14:25 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Bolling
E
0

I think the cause would be revealed if you enable the logs

import boto3
boto3.set_stream_logger('botocore', level='DEBUG')

In my case, I didn't set region name and received that error, but boto3 retires automatically after that with the correct region name

Ecklund answered 25/7 at 12:53 Comment(0)
I
0

try to create that resource manually in aws , if not able to create , change the resource name in terraform script with something unique

Illiterate answered 15/8 at 13:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.