AWS Amplify MissingRequiredParameter userId 错误
AWS Amplify MissingRequiredParameter userId error
我正在按照 Interactions 开始的指南进行操作。当我在 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
属性 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();
那么我在这里错过了什么?
我以前没有用过AWS Amplify所以这个答案可能不是原因,但我以前用过很多次Amazon Lex。这要查找的 UserId 字段可能是 Lex PostText/PostContent 请求的 UserId 参数(请参见下面的代码)
var params = {
botAlias: 'STRING_VALUE', /* required */
botName: 'STRING_VALUE', /* required */
inputText: 'STRING_VALUE', /* required */
userId: 'STRING_VALUE', /* required - THIS IS MISSING FROM YOUR EXAMPLE */
requestAttributes: {
'<String>': 'STRING_VALUE',
/* '<String>': ... */
},
sessionAttributes: {
'<String>': 'STRING_VALUE',
/* '<String>': ... */
}
};
lexruntime.postText(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
var params = {
botAlias: 'STRING_VALUE', /* required */
botName: 'STRING_VALUE', /* required */
contentType: 'STRING_VALUE', /* required */
inputStream: new Buffer('...') || 'STRING_VALUE' || streamObject, /* required */
userId: 'STRING_VALUE', /* required - THIS IS MISSING FROM YOUR EXAMPLE */
accept: 'STRING_VALUE',
requestAttributes: any /* This value will be JSON encoded on your behalf with JSON.stringify() */,
sessionAttributes: any /* This value will be JSON encoded on your behalf with JSON.stringify() */
};
lexruntime.postContent(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
现在,正如我之前所说,我之前没有使用过 AWS Amplify,所以老实说我不确定,但希望这能为您指明正确的方向。
添加我手动创建的 Bot 时遇到了同样的问题 w/o 使用完整的放大设置,但只是使用放大 React Frontend SDK 来使用 Chatbot-Component。原来我为 Cognito Auth 使用了错误的 identityPoolId
。当使用正确的一个时,可以在 Cognito 联合身份部分中找到 ,错误消失,机器人开始工作。此外,我保证分配给该身份池的 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);
您只需使用具有“运行 AWS lex chatbot”权限角色 group/policy 附加的用户登录。
我正在按照 Interactions 开始的指南进行操作。当我在 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
属性 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();
那么我在这里错过了什么?
我以前没有用过AWS Amplify所以这个答案可能不是原因,但我以前用过很多次Amazon Lex。这要查找的 UserId 字段可能是 Lex PostText/PostContent 请求的 UserId 参数(请参见下面的代码)
var params = {
botAlias: 'STRING_VALUE', /* required */
botName: 'STRING_VALUE', /* required */
inputText: 'STRING_VALUE', /* required */
userId: 'STRING_VALUE', /* required - THIS IS MISSING FROM YOUR EXAMPLE */
requestAttributes: {
'<String>': 'STRING_VALUE',
/* '<String>': ... */
},
sessionAttributes: {
'<String>': 'STRING_VALUE',
/* '<String>': ... */
}
};
lexruntime.postText(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
var params = {
botAlias: 'STRING_VALUE', /* required */
botName: 'STRING_VALUE', /* required */
contentType: 'STRING_VALUE', /* required */
inputStream: new Buffer('...') || 'STRING_VALUE' || streamObject, /* required */
userId: 'STRING_VALUE', /* required - THIS IS MISSING FROM YOUR EXAMPLE */
accept: 'STRING_VALUE',
requestAttributes: any /* This value will be JSON encoded on your behalf with JSON.stringify() */,
sessionAttributes: any /* This value will be JSON encoded on your behalf with JSON.stringify() */
};
lexruntime.postContent(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
现在,正如我之前所说,我之前没有使用过 AWS Amplify,所以老实说我不确定,但希望这能为您指明正确的方向。
添加我手动创建的 Bot 时遇到了同样的问题 w/o 使用完整的放大设置,但只是使用放大 React Frontend SDK 来使用 Chatbot-Component。原来我为 Cognito Auth 使用了错误的 identityPoolId
。当使用正确的一个时,可以在 Cognito 联合身份部分中找到 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);
您只需使用具有“运行 AWS lex chatbot”权限角色 group/policy 附加的用户登录。