-1

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
therealbappi
  • 115
  • 1
  • 10

1 Answers1

1

User: arn:aws:sts::524709025091:assumed-role/LF0-role-0nuz6ho1/LF0 is not authorized to perform: lex:RecognizeText

This means that the role that your Lambda is assuming for execution, does not have permission to perform lex:RecognizeText.

You can either:

  1. Create an inline policy granting access to lex:RecogniseText on the Lambda execution role

  2. Attach the AWS managed AmazonLexRunBotsOnly policy to the role, if you also require access to other common Lex APIs

Ermiya Eskandary
  • 15,323
  • 3
  • 31
  • 44