hR 312
hR 312

Reputation: 854

Error while calling amazon lex from aws lambda using boto3

I have published a Lex bot and a Lambda function on the same region. I am trying to interact with Lex from Lambda using following code.

import boto3 
client = boto3.client('lex-runtime')

def lambda_handler(event, context):
    response = client.post_text(
      botName='string',
      botAlias='string',
      userId='string',
      # sessionAttributes={
      #     'string': 'string'
      # },
      # requestAttributes={
      #     'string': 'string'
      # },
      inputText='entity list'
    )
    return response

While testing the code my lambda function is getting timed out. Kindly let me know if you need to know anything else.

Error Message:

"errorMessage": "2021-04-30T07:09:45.715Z <req_id> Task timed out after 183.10 seconds"

Upvotes: 2

Views: 807

Answers (1)

Marcin
Marcin

Reputation: 238081

Lambda in a VPC, including a default VPC, does not have internet access. Since your lambda in a default VPC, it will fail to connect to any lex-runtime AWS endpoint, resulting in a timeout.

Since lex does not support VPC endpoints, the only way for your lambda to access the lex-runtime is:

  • disassociated your function from VPC. If you do this, your function will be able to connect to the internet, and subsequently to lex-runtime.

  • create a private subnet in a default VPC, and setup a NAT gateway. Then place your function in the new subnet. This way your function will be able to connect to the internet using NAT.

More info is in:

Upvotes: 2

Related Questions