How to resolve this AWMS lambda error - An error occured: Received an error response from Lambda: Unhandled?

I'm new to AWS. I am creating a chatbot using aws lex and aws lambda C #. I am using c # aws lmsda program

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;
            }
        }
    }
}

      

I created a slot in aws lex to display the first input parameter . But I always get this error An error occured: Received response from Lambda: Unhandled

On the chrome network tab, I could see Error 424 Failed Dependency which is authentication related.

Help troubleshoot AWS lambda C # bug which is being used by aws lex. I came across a cloud screen but I'm not sure about this.

Thank!

+3


source to share


2 answers


Here's what worked for me:

Lex sends a request to LexEvent

Class Type and waits for a response to LexResponse

Class Type. So I changed my parameter from string

to LexEvent

and returned the type from string

to 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
    }

      

But I'm not sure about the root cause of the problem.

0


source


The connection between Lex and Lambda is not direct like regular functions. Amazon Lex expects Lambda to output in a specific JSON format, and data such as slot data etc. is also sent to Lambda in a similar JSON. You can find blueprints for them here: Format for inputting events and responding to a lambda function . Make sure your C # code also returns JSON in the same way so Lex can understand and do further processing.



Hope it helps!

+3


source







All Articles