【发布时间】: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 用户配置文件。
遵循这两个指南:
- https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-integrating-user-pools-with-identity-pools.html
- 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