我正在尝试在我的网络应用程序中集成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',
});
&#13;
但每次我收到&#34;在配置中缺少凭据&#34;错误。我也尝试过使用AWSCognito.config.credentials,但它仍然给出了同样的错误。任何帮助将不胜感激。
答案 0 :(得分:1)
您是否正在进行以下调用以获取凭据?
// 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()之后立即存在凭证。