我想通过将一个输入(话语)传递给我的bot来从lambda函数调用我的lex bot.

以下是我的Python代码:

import boto3
import json

def lambda_handler(event, context):
    print(event)
    # Create a new Amazon Lex runtime client
    client = boto3.client('lex-runtime')

    # Send the user's input to the bot
    response = client.post_text(
        botName='BotName',
        botAlias='BotAlias',
        userId='UserID',
        inputText=event['input']
    )

    # Return the bot's response to the caller
    return {
        'output': response['message']
    }

我得到以下错误:

"errorMessage":"无法连接到终结点url:"https://runtime.lex.af-south-1.amazonaws.com/bot/BotName/alias/BotAlias/user/UserID/text"", "errorType":"EndpointConnectionError",

我的lambda函数具有以下权限: AmazonLexFullAccess AmazonLexRunBotsOnly

我的Lex机器人拥有基本的Amazon Lex权限.

推荐答案

结果,我使用的是‘lex-run’,而不是‘lexv2-run’.这些参数也必须改变.

更正后的代码如下:

import boto3
import json

def lambda_handler(event, context):
    # Create a new Amazon Lex runtime client
    client = boto3.client('lexv2-runtime')
    
    # Send the user's input to the bot
    response = client.recognize_text(
        botId='<botId>',
        botAliasId='<botAliasId>',
        localeId='<localeId>',
        sessionId='<sessionId>',
        text='event['input']
    )
    
    # Return the bot's response to the caller
    return {
        'output': response['messages']
    }

Python相关问答推荐

线性模型PanelOLS和statmodels OLS之间的区别

如何标记Spacy中不包含特定符号的单词?

输出中带有南的亚麻神经网络

使可滚动框架在tkinter环境中看起来自然

删除字符串中第一次出现单词后的所有内容

Python—从np.array中 Select 复杂的列子集

对象的`__call__`方法的setattr在Python中不起作用'

ThreadPoolExecutor和单个线程的超时

UNIQUE约束失败:customuser. username

将pandas导出到CSV数据,但在此之前,将日期按最小到最大排序

在www.example.com中使用`package_data`包含不包含__init__. py的非Python文件

如何防止Pandas将索引标为周期?

基于多个数组的多个条件将值添加到numpy数组

在Google Drive中获取特定文件夹内的FolderID和文件夹名称

如何使用pytest在traceback中找到特定的异常

SpaCy:Regex模式在基于规则的匹配器中不起作用

如何提高Pandas DataFrame中随机列 Select 和分配的效率?

在不中断格式的情况下在文件的特定部分插入XML标签

Numpy`astype(Int)`给出`np.int64`而不是`int`-怎么办?

使用美汤对维基百科表格进行网络刮擦未返回任何内容