无法通过AWS-SDK节点JS连接到AWS

时间:2019-07-25 08:52:17

标签: node.js aws-sdk-nodejs

我是AWS SDK的新手,正在尝试遵循那里的文档。 https://aws.amazon.com/developers/getting-started/nodejs/我正在尝试创建一个存储桶并在那里上传一些文本文件。但是我遇到了下面提到的错误。

{错误:连接ETIMEDOUT 52.216.206.51:443     在TCPConnectWrap.afterConnect上[作为oncomplete](net.js:1104:14)   消息:'连接ETIMEDOUT 52.216.206.51:443',   errno:“ ETIMEDOUT”,   代码:“ NetworkingError”,   syscall:“连接”,   地址:“ 52.216.206.51”,   端口:443,   地区:“ us-east-1”,   主机名:    'node-sdk-sample-c58bc12a-70be-4578-9c18-1c815962653b.s3.amazonaws.com',   可重试:是的,   时间:20

我尝试在userid / .aws / credentials下的凭证文件中提供凭证

redirect_uris
    A list of the registered redirect uris

我还尝试在代码本身中提供凭据

[default]
aws_access_key_id = my cred...
aws_secret_access_key = my cred....

2 个答案:

答案 0 :(得分:0)

const AWS = require('aws-sdk'); //require aws sdk library

var params = {
Bucket: awsBucketName,
Key: path + fileName,
Body: value.data
};

//s3 upload start
s3bucket.upload(params, (err, data) => {
if (err) {
  return reject(err);
}
return resolve(data.key);
});

//get signed url for downloading the uploaded file
const url = await s3bucket.getSignedUrl('getObject', {
  Bucket: awsBucketName,
  Key: key,
  Expires: 60*3
});

答案 1 :(得分:0)

我能够解决此问题。该问题与代理有关。我试图从防火墙后面访问此文件。配置代理设置后,我可以连接到AWS。

var proxy = require('proxy-agent'); 
AWS.config.update({ httpOptions: { agent: proxy('ur proxy url') } });