When attempting to upload an object to Amazon S3 using their JavaScript SDK, I encounter the following error message:
<Error>
<Code>AuthorizationHeaderMalformed</Code>
<Message>The authorization header is malformed; the region 'us-east-1' is incorrect; expecting 'eu-west-1'</Message>
<Region>eu-west-1</Region>
<RequestId>62D2D18E5093BF1D</RequestId>
<HostId>87ixJCkZyInIVI9BH4zdxtNzFuydwByK6ibvXOICXoE6ZQMp+lWf9RxetaL9c5qFEZEWW/RYdFQ=</HostId>
</Error>
This error occurs when making a HTTP request to .
I have attempted to specify the region multiple times in my code without success.
Below is how I am initializing the S3 client:
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'
});
What could be causing the reference to us-east-1
in the error response despite setting the region correctly?
UPDATE: I have revised the setup code several times and ended up with the following:
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 here is the code responsible for uploading the file:
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);