使用 AWS.CognitoIdentityCredentials 时接收 "Missing credentials in config"
Receiving "Missing credentials in config" when using AWS.CognitoIdentityCredentials
我正在尝试将 lex bot 集成到我的网络应用程序中,这是我编写的代码。我为未经身份验证的用户使用了身份池。这是我的代码
<!DOCTYPE html>
<html>
<head>
<title>Amazon Lex for JavaScript - Sample Application (BookTrip)</title>
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.41.0.min.js"></script>
// Initialize the Amazon Cognito credentials provider
AWS.config.region = 'us-east-1'; // Region
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
// Provide your Pool Id here
IdentityPoolId: 'us-east-1:xxxxxxxxxxxxx',
RoleArn: 'arn:aws:cognito-identity:us-east-1:xxxxxxxxxxxx',
});
但每次我都会收到 "Missing credentials in config" 错误。我也尝试过为此使用 AWSCognito.config.credentials 但它仍然给出相同的错误。任何帮助将不胜感激。
您是否正在进行以下调用以获取凭据?
// Make the call to obtain credentials
AWS.config.credentials.get(function(){
// Credentials will be available when this function is called.
var accessKeyId = AWS.config.credentials.accessKeyId;
var secretAccessKey = AWS.config.credentials.secretAccessKey;
var sessionToken = AWS.config.credentials.sessionToken;
// Add your code here that uses the credentials
});
// Do NOT assume that the credentials are valid here
注意:在调用回调函数之前,凭据不可用。一个常见的错误是在回调之外编写代码,假设在调用 AWS.config.credentials.get().
后凭据立即存在
我正在尝试将 lex bot 集成到我的网络应用程序中,这是我编写的代码。我为未经身份验证的用户使用了身份池。这是我的代码
<!DOCTYPE html>
<html>
<head>
<title>Amazon Lex for JavaScript - Sample Application (BookTrip)</title>
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.41.0.min.js"></script>
// Initialize the Amazon Cognito credentials provider
AWS.config.region = 'us-east-1'; // Region
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
// Provide your Pool Id here
IdentityPoolId: 'us-east-1:xxxxxxxxxxxxx',
RoleArn: 'arn:aws:cognito-identity:us-east-1:xxxxxxxxxxxx',
});
但每次我都会收到 "Missing credentials in config" 错误。我也尝试过为此使用 AWSCognito.config.credentials 但它仍然给出相同的错误。任何帮助将不胜感激。
您是否正在进行以下调用以获取凭据?
// Make the call to obtain credentials
AWS.config.credentials.get(function(){
// Credentials will be available when this function is called.
var accessKeyId = AWS.config.credentials.accessKeyId;
var secretAccessKey = AWS.config.credentials.secretAccessKey;
var sessionToken = AWS.config.credentials.sessionToken;
// Add your code here that uses the credentials
});
// Do NOT assume that the credentials are valid here
注意:在调用回调函数之前,凭据不可用。一个常见的错误是在回调之外编写代码,假设在调用 AWS.config.credentials.get().
后凭据立即存在