Lambda response not being sent back to Lex

0

Hi, I have a lex bot that is calling a lambda function, the functionality works as expected and the lambda logs is displaying the response just fine but the response is not being sent back to Lex. There are no errors. What am I missing? response = { "sessionState":{ "sessionAttributes":session_attributes, "dialogAction":{ "type":"Close" }, "intent": { "name": intent_name, "state": "Fulfilled" } }, "messages":[ { "contentType":"PlainText", "content":"I have recorded your response" } ], }

asked 10 months ago487 views
2 Answers
0

Your response format seems to be incorrect, which might be the reason why it's not being sent back to Lex.

According to the Amazon Lex documentation, the dialogAction and intent fields should be at the same level in the sessionState object, not nested. The dialogAction field itself should contain the type, fulfillmentState, and message.

Here is an example of a correct response structure:

response = {
  "sessionState": {
    "sessionAttributes": session_attributes,
    "dialogAction": {
      "type": "Close",
      "fulfillmentState": "Fulfilled",
      "message": {
        "contentType": "PlainText",
        "content": "I have recorded your response"
      }
    },
    "intent": {
      "name": intent_name,
      "state": "Fulfilled"
    }
  }
}

Please adjust your response format accordingly and see if that resolves the issue. Note that in the above response format, the message field has been moved under the dialogAction field. The fulfillmentState field has also been added.

It's always important to carefully verify the response structure when working with AWS services, as incorrect structures can cause responses to be dropped without raising explicit errors. I've used the following documentation page as reference: DialogAction

Please try again with this updated response structure and let me know if the issue persists.

profile picture
EXPERT
answered 10 months ago
  • Hi, thanks for your quick response. Is your response specific to Lex V1, I am following the V2 documentation. I am sorry I forgot to mention that my bot is V2.

0

I would recommend checking the permissions attached to the IAM role being used as the Lambda execution role. Amazon Lex defines the service-linked role with predefined permissions you should be using. You can read about what permissions you need in your role here under the Roles and permissions section: https://docs.aws.amazon.com/lambda/latest/dg/services-lex.html

Here is a link where you can read more about the response format if you want to double check that as well, as the response format being invalid will also cause issues: https://docs.aws.amazon.com/lexv2/latest/dg/lambda-response-format.html

profile pictureAWS
answered 10 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions