AWS开发工具包S3缺少凭证

时间:2018-09-20 14:24:09

标签: javascript node.js amazon-web-services express amazon-s3

尝试使用aws-sdk节点模块,但是在尝试将文件上传到存储桶时,我一直遇到丢失遗漏的错误。

这是服务器上的错误:

8:16:09 AM web.1 |  CredentialsError: Missing credentials in config
8:16:09 AM web.1 |      at ClientRequest.<anonymous> (/Users/reid/Desktop/DupeFinder/server/node_modules/aws-sdk/lib/http/node.js:83:34)
8:16:09 AM web.1 |      at Object.onceWrapper (events.js:313:30)
8:16:09 AM web.1 |      at emitNone (events.js:106:13)
8:16:09 AM web.1 |      at ClientRequest.emit (events.js:208:7)
8:16:09 AM web.1 |      at Socket.emitTimeout (_http_client.js:706:34)
8:16:09 AM web.1 |      at Object.onceWrapper (events.js:313:30)
8:16:09 AM web.1 |      at emitNone (events.js:106:13)
8:16:09 AM web.1 |      at Socket.emit (events.js:208:7)
8:16:09 AM web.1 |      at Socket._onTimeout (net.js:410:8)
8:16:09 AM web.1 |      at ontimeout (timers.js:498:11)
8:16:09 AM web.1 |      at tryOnTimeout (timers.js:323:5)
8:16:09 AM web.1 |      at Timer.listOnTimeout (timers.js:290:5)

这是给我这个错误的后端:

let s3 = new aws.S3()

app.use(express.static('./public'))
 aws.config = new aws.Config();
let myCredentials = new aws.CognitoIdentityCredentials({IdentityPoolId:'IDENTITY_POOL_ID'}); 
aws.config.update({
    accessKeyId: "xxxxxx",
    secretAccessKey: "xxxxxx",
    region: 'us-east-1';
})

var upload = multer({
  storage: mults3({
    s3: s3,
    bucket: 'dupefinderuseruploads',
    metadata: function (req, file, cb) {
      cb(null, {fieldName: file.fieldname});
    },
    key: function (req, file, cb) {
      cb(null, Date.now().toString())
    }
  })
})



app.post('/uploads', upload.single('Ncsv'), function(req, res, next) {
     res.send('Successfully uploaded ' + req.files.length + ' files!')
})

我清除了访问密钥和秘密密钥,但实际上并未使用xxxxxx。

无论如何。我想我只需要在aws.config.update中添加一个Cradentials键,但是首先,idk该对象的键是什么,其次,idk在Amazon s3中的哪里找到该键的值。

P.S。即时通讯使用multerS3,因为我最初使用multer构建了应用程序,并且可以正常工作。在这里使用multers3并不是问题。

有人可以为此指出正确的方向吗?我不太确定该去哪里寻找,并且谷歌搜索似乎是一个死胡同。

我有文档中显示的myCredintials变量,但我无法确切知道该变量在做什么。

0 个答案:

没有答案