使用aws-amplify的节点的存储(S3)时出现“无凭据”错误

时间:2020-04-17 17:08:23

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

尝试从S3的存储桶中获取图像时,出现错误“无凭据”:

import React, { Component } from 'react'
import { Auth, Storage } from 'aws-amplify'


componentDidMount(){

Storage.get('random-image.jpg')
                .then(data => {
                    console.log(data)
                }).catch(err => console.log(err))
         
}

对于我所听到的我需要添加一个身份联合池的信息,我正在努力了解aws-amplify和aws-sdk之间的区别是什么,尤其是在我的应用程序中确切要放置联合身份的地方池网址以使其正常工作。

这是我的代码,到目前为止,我正在使用cognito服务来允许用户注册和登录,并使用S3来使用户能够上载图像。

Amplify.configure({
    Auth: {
        mandatorySignId: true,
        region: config.cognito.REGION,
        userPoolId: config.cognito.USER_POOL_ID,
        userPoolWebClientId: config.cognito.APP_CLIENT_ID
    },
    Storage: {
        AWSS3: {
            bucket: config.s3.bucket,
            region: config.s3.region, 
        }
    }
})

但是,现在我需要实现必要的代码,以便能够向S3存储桶发出GET请求,并且从我已阅读的内容中,我需要打开一个与我的Cognito用户池相关的联合身份池,并且然后将此代码粘贴到应用中:

AWS.config.region = 'eu-west-2'; // Region
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
    IdentityPoolId: 'eu-west-2:70614759-5f98-48*******',
});

但这不是aws-amplify,而是aws-sdk。我尝试导入aws-sdk并粘贴该代码,但无法正常工作。 我可以将这些信息放入Amplify.configure语句中吗?在此页面https://aws-amplify.github.io/docs/js/storage之后,它说我可以,所以我做到了:

Auth: {
        mandatorySignId: true,
        region: config.cognito.REGION,
        userPoolId: config.cognito.USER_POOL_ID,
        userPoolWebClientId: config.cognito.APP_CLIENT_ID
        // add the identity federated:
        identityPoolId: config.cognito.IDENTITY_POOL
    },

现在它给了我Missing credentials in config

0 个答案:

没有答案