Lambda function to query Kendra for Lex Response


I am trying to write a Lambda function to filter a SearchKendra intent on Lex v2. I would like to filter based on 'accountId', which I have assigned to a document in the relevant bucket by including a .metadata file in the same location.

Here is my current Lambda function followed by the error that I am receiving. Any ideas what might be going on?


def lambda_handler(event, context):
    kendraQuery = {
    	"AttributeFilter": {
    		"EqualsTo": {
    			"Key": "accountId",
    			"Value": {
    				"StringValue": "123testid"
    	"IndexId": "sample-faq-index"
    return {
        	"dialogAction": {
        		"type": "Delegate",
        		"kendraQueryRequestPayload": kendraQuery

Here is the error message in the Lex console when testing:

Invalid Lambda Response: Received invalid response from Lambda: Can not construct instance of IntentResponse, problem: The validated object is null at [Source: {"dialogAction": {"type": "Delegate", "kendraQueryRequestPayload": {"AttributeFilter": {"equalsTo": {"key": "accountId", "value": {"stringValue": "123testid"}}}, "IndexId": "sample-faq-index"}}}; line: 1, column: 194]

asked a year ago183 views
2 Answers

Hey, can you provide the actual Kendra query request payload that you are performing. from the request payload you provided, it looks like that this is an invalid query.

if you are trying to do a queryless search, you need to make sure both attributeFilter and SortingConfiguration are provided


answered 10 months ago
  • This is a lambda function for Lex to query Kendra. Can you provide an example of a lambda function for this purpose that filters documents based on an attribute filter as above? I believe the payload would be the Lex responses, which are included in the intent. They are of the format:

    I found a FAQ question for you: ((x-amz-lex:kendra-search-response-question_answer-question-1)) and the answer is ((x-amz-lex:kendra-search-response-question_answer-answer-1)).

    I found an excerpt from a helpful document: ((x-amz-lex:kendra-search-response-document-1)).

    I think the answer to your questions is ((x-amz-lex:kendra-search-response-answer-1)).



Your Lambda can provide two attributes to Lex that can be used for Kendra queries: kendraQueryFilterString, and kendraQueryRequestPayload.

kendraQueryRequestPayload requires the entire Kendra query object, while kendraQueryFilterString is only the attribute filter. Looks like what you are looking for is kendraQueryFilterString.

You can see more details here:

I hope this helps!


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