通过makeUnauthenticatedRequest访问JS AWS S3公共存储桶:"网络故障"?

时间:2016-07-08 12:24:10

标签: javascript amazon-web-services networking amazon-s3 network-programming

我试图通过以下方式访问AWS S3上的公共存储桶:

....

<script src="https://sdk.amazonaws.com/js/aws-sdk-2.4.5.min.js"></script>

....
    const AWS = window.AWS;

    AWS.config.region = 'eu-central-1';

    let params =
    {
        Bucket: bucketPath,
           Key: fileKey
    }

    let s3 = new AWS.S3();

    s3.makeUnauthenticatedRequest('getObject', params, function (err, data)
    {
        if (err)
        {
            console.log(err);
        }
        else
        {
            console.log( data.Body.toString() );
        }
    });
....

不幸的是,我收到了这个错误:

{
 "message": "Network Failure",
 "code": "NetworkingError",
 "time": "2016-07-08T12:13:34.050Z",
 "region": "us-east-1",
 "hostname": "s3.amazonaws.com",
 "retryable": true
}

我猜,问题可能与该地区有关:我正在尝试设置eu-central-1,但错误是指我们 - 东 - 1 ...我的代码出了什么问题?

非常感谢任何提示。

1 个答案:

答案 0 :(得分:0)

好的,我们不能假设构造函数可以找到正确的区域本身,因此我区域的s3的正确实例化是:

let s3 = new AWS.S3({region: 'eu-central-1', maxRetries: 15});