AWS Amplify MissingRequiredParameter userId错误 [英] AWS Amplify MissingRequiredParameter userId error

查看:137
本文介绍了AWS Amplify MissingRequiredParameter userId错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在遵循从互动开始的指南.当我在Interactions上调用 send 方法时,出现以下错误:

I'm following the guide for starting with Interactions. When I call the send method on Interactions, I get the following error:

(节点:27796)UnhandledPromiseRejection警告:MissingRequiredParameter:参数中缺少必需的键'userId'

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

Interactions似乎期望使用 userId 参数,该参数应从 @ aws-amplify/interactions/lib/Providers/AWSLexProvider.js 中提取 credentials.identityId .但是,当我登录 credentials 时,它是 SharedIniFileCredentials 类型,它没有 identityId 属性

It looks like Interactions is expecting a userId param, which in @aws-amplify/interactions/lib/Providers/AWSLexProvider.js, is supposed to be pulled from credentials.identityId. However, when I log credentials, it is type SharedIniFileCredentials, which does not have an identityId property according to the documentation.

读取文档 identityId必须是Cognito用户. AWSLexProvider.js 不会尝试调用 CognitoIdentityCredentials 来获取Cognito凭据.

From reading the docs, identityId would have to be a Cognito user. AWSLexProvider.js makes no attempt at calling CognitoIdentityCredentials to get Cognito credentials.

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

Hence, I am not sure where identityId is supposed to come from.

我的代码是Amplify网站上的示例:

My code is the example from the Amplify website:

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时,我遇到了同样的问题,该Bot是我使用完整的放大设置手动创建的,但没有使用放大的React Frontend SDK来使用聊天机器人组件.原来我为Cognito Auth使用了错误的 identityPoolId .使用正确的地址时,可以在此处找到的位置,错误消失了,机器人开始工作了.另外,我保证分配给该身份池的 custom_auth_role 在操作下还具有以下属性:

I had the same issue when adding a Bot which i creatred manually w/o using the full amplify setup, but just using the amplify React Frontend SDK to use the Chatbot-Component. Turned out that I used the wrong identityPoolIdfor Cognito Auth. When using the right one, which can be found as described here where to find identity pool id in the cognito federeated identities section, the error disappeared and the bots started working. Additionally I assured that the custom_auth_role assigned to that identity pool has addtionally the following properties under actions:

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

这可以在该角色的IAM->角色部分中提出.不知道这是否是绝对必要的.

This can be assgined in the IAM -> Roles Section for that role. Not sure if that is absolutely required though.

所以最终这是它的样子:

So finally this is what it looks like:

    //...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 Amplify MissingRequiredParameter userId错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆