Lambda function is not recognizing LexBot

Viewed 593

I have created simple Lambda function (simple nodejs application) and trying to integrate with Lex bot. have followed the aws doc and created the execution role. configured the lex bot with proper alias and associated the version as well.

this is the doc being followed

when I am testing the lambda function execution it throws following error:

{
  "errorType": "BadRequestException",
  "errorMessage": "INVALID_REQUEST - Invalid bot name or alias",
  "trace": [
    "BadRequestException: INVALID_REQUEST - Invalid bot name or alias",
    "    at Object.extractError (/var/task/node_modules/aws-sdk/lib/protocol/json.js:52:27)",
    "    at Request.extractError (/var/task/node_modules/aws-sdk/lib/protocol/rest_json.js:55:8)",
    "    at Request.callListeners (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:106:20)",
    "    at Request.emit (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:78:10)",
    "    at Request.emit (/var/task/node_modules/aws-sdk/lib/request.js:688:14)",
    "    at Request.transition (/var/task/node_modules/aws-sdk/lib/request.js:22:10)",
    "    at AcceptorStateMachine.runTo (/var/task/node_modules/aws-sdk/lib/state_machine.js:14:12)",
    "    at /var/task/node_modules/aws-sdk/lib/state_machine.js:26:10",
    "    at Request.<anonymous> (/var/task/node_modules/aws-sdk/lib/request.js:38:9)",
    "    at Request.<anonymous> (/var/task/node_modules/aws-sdk/lib/request.js:690:12)"
  ]
}

bot name and alias is valid. i checked that. still it throws error. how to debug this?

3 Answers

I am facing the same thing, aws lex-models get-bots returns an empty list although bots are present.

aws lexv2-runtime recognize-text --bot-id <botId> --bot-alias-id TSTALIASID --locale-id 'en_GB' --session-id 'test_sessio1n' --text 'my input test'

The above gives a proper response.

I am guessing this is an issue with Lex v1 vs v2.

In the Lex Bot make sure you create a separate alias from the default one that is present and try it. Also, ensure to provide the right alias ID and the bot ID in your code.

I encountered the same error when trying to use the @aws_sdk/client-lex-runtime-service client's PutText command (which uses the botName and botAlias) with a Lex V2 chatbot, which apparently isn't compatible. The fix was to use the newer @aws-sdk/client-lex-runtime-v2 client's RecognizeText command (which uses the botAliasId, botId, localeId and sessionId).

Related