3

こんにちは、

AWS 製品 API への接続をセットアップしようとしていますが、次のように 301 Permanent Redirect Error が引き続き発生します。

{ [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 }

API への接続に使用しているコードは次のとおりです。

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");
    });
});

us-west-1 のように別のリージョンを使用しようとすると、同じエラーが発生します。

私は何を間違っていますか?

事前にどうもありがとうございました!

4

3 に答える 3

2

しばらくこれに引っかかった…

地域名を設定することも、構成ファイルで空白のままにすることも、問題を解決しませんでした。私は解決策について話している要点に出くわしましたが、それは非常に簡単でした:

与えられた:

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

S3 オブジェクトをインスタンス化する前に、次のことを行います。

AWS.config.update({"region": "us-west-2"}) //replacing your region there

その後、問題なく以下を呼び出すことができました。

var storage = new AWS.S3();
var params = {
                Bucket: config.aws.s3_bucket,
                Key: name,
                ACL:'authenticated-read',
                Body: data
            }
storage.putObject(params, function(storage_err, data){...})
于 2014-06-24T23:24:52.233 に答える