Node.js 303 Permanent Redirect when connecting to AWS-SDK
10:14 20 Apr 2013

I'm trying to set up a connection to my AWS product API, however I keep getting a 301 Permanent Redirect Error as follows:

{ [PermanentRedirect: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.]
  message: 'The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.',
  code: 'PermanentRedirect',
  name: 'PermanentRedirect',
  statusCode: 301,
  retryable: false }

The code I am using to connect to the API is as follows:

var aws = require('aws-sdk');

//Setting up the AWS API
aws.config.update({
    accessKeyId: 'KEY',
    secretAccessKey: 'SECRET',
    region: 'eu-west-1'
})

var s3 = new aws.S3();

s3.createBucket({Bucket: 'myBucket'}, function() {
    var params = {Bucket: 'myBucket', Key: 'myKey', Body: 'Hello!'};
    s3.putObject(params, function(err, data) {
        if (err)
            console.log(err)
        else
            console.log("Successfully uploaded data to myBucket/myKey");
    });
});

If I try using different regions, like us-west-1 I just get the same error.

What am I doing wrong?

javascript node.js amazon-web-services amazon-s3 http-status-code-301