I am trying to access amazon lex from a lambda function. Lambda function sends the input message from the chat bot to lex. When I try to send the text,it is giving me an error.
errorMessage: "An error occurred (AccessDeniedException) when calling the RecognizeText operation: User: arn:aws:sts::524709025091:assumed-role/LF0-role-0nuz6ho1/LF0 is not authorized to perform: lex:RecognizeText on resource: arn:aws:lex:us-east-1:524709025091:bot-alias/1TN1TWNYYG/TSTALIASID because no identity-based policy allows the lex:RecognizeText action"
errorType: "AccessDeniedException"
requestId: "45ee975b-ecfa-4823-837b-790cdd908a5b"
The code in my lambda function:
import json
import random
import boto3
def lambda_handler(event, context):
responsemsg = ''
for msg in event['messages']:
responsemsg += msg['unstructured']['text']
session = boto3.Session()
client = boto3.client('lexv2-runtime')
response = client.recognize_text(
botId='****',
botAliasId='****',
localeId='en_US',
sessionId="test_session",
text='hi')
return response