gpt4 book ai didi

amazon-web-services - AWS Amplify MissingRequiredParameter userId 错误

转载 作者:行者123 更新时间:2023-12-04 13:02:05 30 4
gpt4 key购买 nike

我正在遵循从 Interactions 开始的指南.当我拨打 send关于交互的方法,我收到以下错误:

(node:27796) UnhandledPromiseRejectionWarning: MissingRequiredParameter: Missing required key 'userId' in params



看起来 Interactions 需要一个 userId 参数,在 @aws-amplify/interactions/lib/Providers/AWSLexProvider.js 中, 应该是从 credentials.identityId 拉出来的.但是,当我登录 credentials ,它是类型 SharedIniFileCredentials ,它没有 identityId属性(property) according to the documentation .

来自 reading the docs , identityId必须是 Cognito 用户。 AWSLexProvider.js不尝试拨打 CognitoIdentityCredentials获取 Cognito 凭据。

因此, 我不确定在哪里identityId应该来自 .

我的代码是来自 Amplify 网站的示例:
import Amplify, { Interactions } from 'aws-amplify';
import aws_exports from './aws-exports';

Amplify.configure(aws_exports);

async function test() {
let userInput = "I want to reserve a hotel for tonight";

// Provide a bot name and user input
const response = await Interactions.send("BookTrip", userInput);

// Log chatbot response
console.log (response['message']);
}

test();


那么我在这里错过了什么?

最佳答案

在添加我使用完整的放大设置手动创建的 Bot 时,我遇到了同样的问题,但只使用放大 React Frontend SDK 来使用 Chatbot 组件。原来我用错了identityPoolId用于 Cognito 身份验证。使用正确的方法时,可以按照此处的说明找到该方法 where to find identity pool id在认知联合身份部分,错误消失,机器人开始工作。另外我保证,custom_auth_role分配给该身份池的操作还具有以下属性:

            "Action": [
...
"lex:PostContent",
"lex:PostText"
],

这可以在 IAM -> 角色部分中为该角色分配。不确定这是否绝对需要。

所以最后这是它的样子:
    //...all other React imports, etc
import { ChatBot, withAuthenticator } from "aws-amplify-react";
import Amplify, { Auth } from "aws-amplify";

Amplify.configure({
Auth: {
identityPoolId: "eu-west-1:XX-XX-XX-XXX-XXX", //<-here the right Id needs to be set
region: "eu-west-1",
userPoolId: "eu-west-1_XXXXXX",
userPoolWebClientId: "XXXXXX"
},
Interactions: {
bots: {
botNameAsInAwsConsole: {
name: "someName",
alias: "$LATEST",
region: "eu-west-1"
}
}
}
});

function App() {
return (
<ChatBot
title="Demo Bot"
theme={myTheme}
botName="botNameAsInAwsConsole"
welcomeMessage="Welcome, how can I help you today?"
onComplete={handleComplete}
clearOnComplete={true}
conversationModeOn={false}
voiceEnabled={false}
/>
);
}

export default withAuthenticator(App, true);

关于amazon-web-services - AWS Amplify MissingRequiredParameter userId 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54148545/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com