【问题标题】:How to fix "CredentialsError: Missing credentials in config" (aws-sdk) in react-native如何在 react-native 中修复“CredentialsError:配置中缺少凭据”(aws-sdk)
【发布时间】:2019-08-27 18:43:02
【问题描述】:

我正在尝试访问 AWS Cognito 的“adminAddUserToGroup”方法 来自我的本机应用程序。我想在他注册后立即将用户添加到特定组。

该方法的文档说“需要开发人员凭据”。 我在系统的 ~/.aws/credentials 中有我的凭据(AccessKey 和 SecretKey)。如何在我的代码中使用它?

    var cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider(
      { region: regionId }
    );
    const params = {
      GroupName: groupName,
      UserPoolId: userPoolId,
      Username: that.state.username
    };
    cognitoidentityserviceprovider.adminAddUserToGroup(
      params,
      (err, data) => {
        if (err) console.log(err);
        else {
          console.log(data);
        }
      }
    );

这会导致错误

    CredentialsError: Missing credentials in config
at credError (blob:http://localhost:8081/6f586340-99cf-40d3-b978-de453021be50:245014:50)
at Config.getCredentials (blob:http://localhost:8081/6f586340-99cf-40d3-b978-de453021be50:245058:24)
at Request.VALIDATE_CREDENTIALS (blob:http://localhost:8081/6f586340-99cf-40d3-b978-de453021be50:245435:36)
at Request.callListeners (blob:http://localhost:8081/6f586340-99cf-40d3-b978-de453021be50:244218:28)
at Request.emit (blob:http://localhost:8081/6f586340-99cf-40d3-b978-de453021be50:244195:20)
at Request.emit (blob:http://localhost:8081/6f586340-99cf-40d3-b978-de453021be50:247081:26)
at Request.transition (blob:http://localhost:8081/6f586340-99cf-40d3-b978-de453021be50:246822:22)
at AcceptorStateMachine.runTo (blob:http://localhost:8081/6f586340-99cf-40d3-b978-de453021be50:247182:22)
at Request.runTo (blob:http://localhost:8081/6f586340-99cf-40d3-b978-de453021be50:246894:27)
at Request.send (blob:http://localhost:8081/6f586340-99cf-40d3-b978-de453021be50:246887:22)

我应该在哪里以及如何添加开发凭据?

【问题讨论】:

    标签: react-native amazon-cognito aws-sdk-js


    【解决方案1】:

    在 react-Native 中,sdk 将无法访问您系统上的文件。您可以像这样在浏览器中设置凭据https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-credentials-browser.html

    【讨论】:

      猜你喜欢
      • 2017-08-31
      • 2019-02-24
      • 1970-01-01
      • 2019-05-05
      • 2020-10-04
      • 1970-01-01
      • 2020-11-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多