2

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?

James Z
  • 12,209
  • 10
  • 24
  • 44
user2315104
  • 2,378
  • 7
  • 35
  • 54
  • Code running in the correct region? Did you validated with awscli (`aws lex-models get-bots`)? – jarmod Sep 15 '21 at 16:19
  • you mean , lex bot and lambda function should be in same region ? – user2315104 Sep 15 '21 at 17:15
  • I don't believe that's necessary, but you're making an API call to the Lex service in a given region. Is that the same region that the lex bot exists in? If you didn't explicitly indicate to the AWS SDK which region you wanted the request to go to, then it will go to the region in which the Lambda itself is running, by default. – jarmod Sep 15 '21 at 17:19
  • I checked , both are in same region, us-west-2 – user2315104 Sep 15 '21 at 17:27
  • You should probably verify the name using the awscli, as mentioned previously. If that doesn't help, then add some code here to show what you're doing. – jarmod Sep 15 '21 at 17:35

3 Answers3

4

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.

0

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.

Vishnu J
  • 89
  • 1
  • 8
0

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).

Kris Dover
  • 544
  • 5
  • 9