【问题标题】:Error: AWS Web RTC Verification with Cognito错误:使用 Cognito 进行 AWS Web RTC 验证
【发布时间】:2021-07-16 23:34:58
【问题描述】:

我正在尝试将我的 javascript 应用程序 AWS WebRTC 与 Cognito 用户连接以动态获取其凭据,但遇到以下错误代码:

json.js:52 Uncaught (in promise) CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1

我已将我的凭据硬编码到配置中,并且它已成功运行,但这是一种不好的做法,因此我试图通过我的 Cognito 用户获取 AWS Web RTC 凭据。我已经设置了用户池并链接到我的联邦身份。凭证现在由 AWS Amplify 管理,它从配置文件 (./aws/credentials) 加载 AWS 用户配置文件。

遵循这两个指南:

  1. https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-integrating-user-pools-with-identity-pools.html
  2. https://docs.aws.amazon.com/cognito/latest/developerguide/getting-credentials.html

我已经编写了以下 sn-p 来获取我的凭据,但现在遇到了错误。

AWS.config.region = '<REGION>';
  AWS.config.update({
    credentials: new AWS.CognitoIdentityCredentials({
      IdentityPoolId: '<Region>:<IdentitiyPoolID>',
      Logins: {
        'cognito-idp.<Region>.amazonaws.com/<UserPoolID> ': <id token from cognito>,
      },
    }),
  });

  var accessKeyId;
  var secretAccessKey;

  AWS.config.credentials.get(function () {
    accessKeyId = AWS.config.credentials.accessKeyId;
    secretAccessKey = AWS.config.credentials.secretAccessKey;
  });

const state = {
    accessKeyId: accessKeyId,
    secretAccessKey: secretAccessKey,
    region: 'region',
}
async function startPlayerForViewer();

非常感谢任何帮助!在网上找不到太多更新的资源/示例。

【问题讨论】:

    标签: reactjs amazon-web-services webrtc amazon-cognito aws-amplify


    【解决方案1】:

    credentials.get() 是一个异步操作,它在回调中接收键,而状态定义发生在接收到回调之前。因此,未设置密钥。您需要确保在回调之后定义状态,并确保在之后发生连接。

    【讨论】:

    • 感谢您帮助我理解我的问题并引导我走向正确的方向。
    猜你喜欢
    • 2018-03-14
    • 2021-06-25
    • 2021-04-28
    • 2019-06-19
    • 2019-10-04
    • 1970-01-01
    • 2017-04-26
    • 1970-01-01
    • 2018-12-09
    相关资源
    最近更新 更多