如何解决此 AWS lambda 错误 - 发生错误:从 Lambda 收到错误响应:未处理?

How to troubleshoot this AWS lambda error - An error has occurred: Received error response from Lambda: Unhandled?

我是 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,但我不确定。

谢谢!

Lex 和 Lambda 之间的通信不像正常函数那样直接。 Amazon Lex 期望 Lambda 以特定的 JSON 格式输出,并且插槽详细信息等数据也以类似的 JSON 格式发送到 Lambda。您可以在这里找到它们的蓝图:Lambda Function Input Event and Response Format。确保您的 C# 代码也以类似的方式 return a JSON,以便 Lex 可以理解并进行进一步处理。

希望对您有所帮助!

以下是对我有用的方法:

Lex 以 LexEvent Class 类型发送请求并期望在 LexResponse Class type.So 中得到响应 我将参数从 string 更改为LexEvent 和 return 输入从 stringLexResponse

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
    }

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