3

我是 AWS 新手。我正在使用 aws lex 和 aws lambda c# 构建聊天机器人。我正在使用示例 aws lambda C# 程序

namespace AWSLambda4
{
    public class Function
    {

        /// <summary>
        /// A simple function that takes a string and does a ToUpper
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public string FunctionHandler(string input, ILambdaContext context)
        {
            try
            {
                return input?.ToUpper();
            }
            catch (Exception e)
            {

                return "sorry i could not process your request due to " + e.Message;
            }
        }
    }
}

我在 aws lex 中创建了一个插槽来映射第一个参数input。但我总是收到此错误发生错误:收到来自 Lambda 的错误响应:未处理

在 Chrome 网络选项卡中,我可以看到与身份验证相关的Error-424 Failed Dependency

请帮助如何解决 aws lex 使用的 AWS lambda C# 错误。我遇到了 cloudwatch,但我不确定。

谢谢!

4

2 回答 2

4

Lex 和 Lambda 之间的通信不像普通函数那样直接。Amazon Lex 期望 Lambda 以特定的 JSON 格式输出,并且槽详细信息等数据也以类似的 JSON 发送到 Lambda。您可以在此处找到它们的蓝图:Lambda 函数输入事件和响应格式。确保您的 C# 代码也以类似的方式返回 JSON,以便 Lex 可以理解并进行进一步处理。

希望能帮助到你!

于 2017-05-18T13:38:30.917 回答
0

这对我有用:

Lex 以 Class 类型发送请求LexEvent并期望以 Class 类型响应。LexResponse所以我将参数从stringto更改为LexEvent返回类型从stringto LexResponse

public LexResponse FunctionHandler(LexEvent lexEvent, ILambdaContext context)
    {
        //Your logic goes here.
        IIntentProcessor process;

        switch (lexEvent.CurrentIntent.Name)
        {
            case "BookHotel":
                process = new BookHotelIntentProcessor();
                break;
            case "BookCar":
                process = new BookCarIntentProcessor();
                break;                
            case "Greetings":
                process = new GreetingIntentProcessor();
                break;
            case "Help":
                process = new HelpIntentProcessor();
                break;
            default:
                throw new Exception($"Intent with name {lexEvent.CurrentIntent.Name} not supported");
        }


        return process.Process(lexEvent, context);// This is my custom logic to return LexResponse
    }

但我不确定问题的根本原因。

于 2017-05-25T06:20:16.343 回答