Reputation: 39389
I’m trying to upload an object to Amazon S3 via their JavaScript SDK, but getting the following error during the upload:
<Error>
<Code>AuthorizationHeaderMalformed</Code>
<Message>The authorization header is malformed; the region 'us-east-1' is wrong; expecting 'eu-west-1'</Message>
<Region>eu-west-1</Region>
<RequestId>62D2D18E5093BF1D</RequestId>
<HostId>87ixJCkZyInIVI9BH4zdxtNzFuydwByK6ibvXOICXoE6ZQMp+lWf9RxetaL9c5qFEZEWW/RYdFQ=</HostId>
</Error>
I get this error response when a HTTP request to https://my-bucket-name.s3.amazonaws.com/?max-keys=0 is made.
I’ve tried setting the region everywhere, but still getting the error.
Here’s what my code instantiating the S3 client looks like:
import AWS from 'aws-sdk';
AWS.config.update({
region: 'eu-west-1',
credentials: new AWS.CognitoIdentityCredentials({
IdentityPoolId: this.identityPoolId
}, {
region: 'eu-west-1'
})
});
this.s3 = new AWS.S3({
apiVersion: '2006-03-01',
params: {
Bucket: this.bucket
},
region: 'eu-west-1'
});
Where am I going wrong? Why is there still a reference to us-east-1
in the above error response when generating the signature?
EDIT: I’ve written and re-written the set-up code a few times over now. This is what I currently have:
const AWS = require('aws-sdk/global');
const S3 = require('aws-sdk/clients/s3');
this.s3 = new S3({
apiVersion: 'latest',
credentials: new AWS.CognitoIdentityCredentials({
IdentityPoolId: this.identityPoolId
}, {
region: 'eu-west-1'
}),
params: {
Bucket: this.bucket
},
region: 'eu-west-1'
});
And then the code that does the actual file upload:
const params = {
ACL: 'private',
Body: this.file,
ContentType: this.file.type,
Key: `videos/input/${this.filename}`
};
this.s3
.putObject(params)
.on('httpUploadProgress', this.onUploadProgress)
.send(this.onSend);
Upvotes: 2
Views: 17438
Reputation: 11
When you get this error it means that the bucket name you have chosen exists somewhere else on Amazon S3, this could be in your account or in another account.
Since S3 uses a single namespace all bucket names have to be unique. If this bucket exists inside your account update your script to point to the actual region where the bucket exists. If it's not in your account then change the bucket name and give it a go.
Upvotes: 1
Reputation: 81356
The issue is caused by your call to CognitoIdentityCredentials
The variable AWS is not setup yet.
Change your code to look like this:
AWS.config.region = 'eu-west-1';
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: this.identityPoolId
});
Upvotes: 1