Lex V2 not invoking Lambda Code Hook after "Success" condition on Slot Elicitation

0

The "Code hook" is not invoking Lambda after a successful slot elicitation (even though Lex indicates Code Hook success) unless I choose to invoke Lambda at every turn. I'd like to limit the use of Lambda to utility functions and have conversation flow and logic in Lex as much as possible.

Where am I going wrong?

---Background---

I'm writing a simple Intent in Lex v2 to get a number of days to schedule a reminder at the date calculated from the duration from the current date. I'm eliciting the duration in a Slot and then storing the calculated date as a Session Variable.

I can get the Lambda code to invoke under the following conditions:

  1. Fulfillment: When "Invoke Lambda" is checked - The is with the message text coming directly from Lambda (with Fulfillment state as "Fulfilled" and dialogAction:type as "Close") or by delegating the response (dialogAction:type as "Delegate") to the Fulfillment "Success Response" which references both duration Slot and calculated date Session Variable values
  2. When the "Code hook - optional" is checked, calling the Lambda at each turn.

The issue with #1 is that waiting until Fulfillment makes the dialog too verbose for my taste (i.e. "What's the duration?" -> "So, {duration} days?" -> "OK, scheduled for [calculated date]" -> "Scheduling successful for [date]") as I'd like to use this in SMS functionality. The user doesn't get to confirm the date, only the duration. The date is what I'd like to be confirmed.

The issue with #2 is that my Lambda function has to be more sophisticated (check for conditions, errors, etc.) and I'd rather only pay for Lambda invocations that actually do something.

Ideally, I'd like this to work like it's pictured here - with the "Code hook" only being called AFTER slot value elicitation and prior to confirmation. So, that I get a more useful confirmation message (i.e a flow that's more like this "What's the duration" -> "You would like to schedule in {duration} days, which would be [calculated date] is this correct?" Lex Flow

I can get the appropriate "Success response" from the Code Hook, but there's zero evidence in CloudWatch that the Lambda function was ever called and the bot fails on fulfillment because the session variable - [calculated_time] - is never set by the Lambda function.

asked a year ago304 views
1 Answer
1

Justin,

By default lambda is enabled at each turn but can be disabled selectively. To disable codehook invocation at 'Get slot value' step:

  1. Click on the Gear icon after 'Slot prompt'

Enter image description here

  1. Uncheck the checkbox for 'Invoke Lambda code hook after each elicitation'

Enter image description here

  1. Save intent and rebuild the bot.

This setting is also available for Confirmation Prompt and the dialog code hook steps. The setting at each conversation step is ignored when the intent level setting of 'Enable dialog code hook invocation' is disabled

AWS
Saket
answered a year ago
  • Thanks for taking the time to address this. What you describe is how I have it configured now. I do get the "Success" response that I typed into the "Code Hook", but Lambda is not invoked. I'd assume that Lambda is configured correctly for this intent as it works in the other conditions (i.e. at every turn and at Fulfillment)

  • Justin, It is difficult to pinpoint the issue without access to you bot definition. But I will suggest to confirm following

    1. Intent level setting of 'Enable dialog code hook invocation' is enabled
    2. Codehook blocks 'Invoke lambda function' setting is enabled
    3. Lambda function is configured under alias setting
    4. Resource Based Policy on Lambda allows Lex calling the Lambda function.

    2 is the most important one to check. Given that codehook invocation is working at other steps, 1, 3 and 4 should be as expected.

    Also, can you confirm that the Success message is unique so that we can know for sure that success path was taken.

  • I did try unchecking the "Invoke Lambda after each elicitation" as shown in the screenshot. No difference.

    1. I don't see the option for #1. I've only seen 1) Invoking at each turn and 2) Invoking at specific places.
    2. Yes, it is
    3. Setup a Lambda alias and...no difference.
    4. There is a resource-based policy already.

    The success message is unique.

    I could share the bot definition with you. There's no "secret sauce". Would an export be sufficient?

  • Yes. an export will be helpful

  • Thanks! What would be the best way to share an export with you?

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