3

I'm new to AWS. I'm build chatbot using aws lex and aws lambda c#. I'm using sample aws lambda C# 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 map first parameter input . But i'm always getting this error An error has occurred: Received error response from Lambda: Unhandled

In Chrome network tab i could see Error- 424 Failed Dependency which is related to authentication.

Please help how to troubleshoot AWS lambda C# error which is used by aws lex. I came across cloudwatch but I'm not sure about that.

Thanks!

ManirajSS
  • 2,295
  • 5
  • 26
  • 50

2 Answers2

4

The communication between Lex and Lambda is not straight forward like normal functions. Amazon Lex expects output from Lambda in a particular JSON format and data like slot details etc are also sent to Lambda in a similar JSON. You can find the blueprints for them here: Lambda Function Input Event and Response Format. Make sure your C# code also return a JSON in the similar fashion, so that Lex can understand and do the further processing.

Hope it helps!

Repakula Srushith
  • 444
  • 1
  • 3
  • 10
  • 1
    Lambda have both handled and un-handled error.Since it is unhandled error the lambda method itself not invoked i guess.And lex console states `Error- 424 Failed Dependency` which is related to authentication.So i think its more related to configuration related error rather than coding related error. – ManirajSS May 23 '17 at 09:08
  • @ManirajSS I have an error which says `Received invalid response from Lambda` and in network tab it seems to be a 424. do you know the possible route cause? – yashhy May 25 '17 at 03:43
  • @yashhy i have resolved my issue. Please see my answer and let me know if you have any doubts. – ManirajSS May 25 '17 at 06:23
0

Here is what worked for me:

Lex sends request in LexEvent Class type and expects response in LexResponse Class type.So i changed my parameter from string to LexEvent and return 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 issue.

ManirajSS
  • 2,295
  • 5
  • 26
  • 50
  • as @Repakula mentioned the 424 error response seems to be a Lex return type issue? and in my case im using nodejs and following the sample structure like stated [here](http://docs.aws.amazon.com/lex/latest/dg/lambda-input-response-format.html#using-lambda-response-format) – yashhy May 25 '17 at 07:43
  • I solved the problem as suggested by @ Repakula see the detailed answer [here](https://stackoverflow.com/a/44182337/1778834) – yashhy May 25 '17 at 13:56