question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

boto3 client for lambda stops reading from a connection after 300 seconds

See original GitHub issue

I have a Lambda function that contains code that needs to execute for 5 minutes or longer. I invoke this Lambda function using boto3 and wait for the response from the Lambda function (response being a json object).

I noticed that on using botocore.config.Config to increase read_timeout for the boto3.client the client keeps the connection open but stops reading from the connection after 300 seconds (5 minutes) and throws a ReadTimeoutError exception after the specified value of the read_timeout parameter.

Below are the code snippets to reproduce the issue:

Client machine code: python: 3.5 OS: Ubuntu 16.04 Linux botocore version: 1.14.11

import json

import boto3
import botocore

config = botocore.config.Config(read_timeout=310, connect_timeout=310, retries={'max_attempts': 0})
client = boto3.client('lambda', config=config)

payload = {"body":some_string}
payload = json.dumps(payload)

response = client.invoke(
            FunctionName='arn:aws:lambda:<region>:xxxxxxxxxxxx:function:function_name',
            InvocationType='RequestResponse',
            Payload=payload
        )

Lambda function code: python: 3.7

import time
import json

def lambda_handler(event, context):
    time.sleep(300)
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }

The above code produces the following error message: botocore.exceptions.ReadTimeoutError: Read timeout on endpoint URL after 310 seconds. I have tried experimenting with multiple values of time.sleep() and read_timeout. After referring to the CloudWatch logs I am fairly certain this only happens if Lambda executes for 300 seconds or more (the same can be verified by changing the sleep time in Lambda to 299)

I have referred to the issue #1104 and #205. What seems to be the issue here? Any help would be much appreciated.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
arcadecoffeecommented, Jun 24, 2020

We’re experiencing an issue exactly like what is described above. Was there ever any real resolution here?

0reactions
swetashrecommented, Mar 23, 2020

Closing this issue due to inactivity. Please reopen if you have any questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot Lambda function retry and timeout issues when ...
When I invoke my AWS Lambda function using an AWS SDK, the function times ... Python (Boto 3), depends on service, 60 seconds,...
Read more >
class Lambda. Client - Boto3 Docs 1.26.34 documentation
Note: Lambda does not support adding policies to version $LATEST. ... to any value from 0 seconds to 300 seconds in increments of...
Read more >
Python request in AWS Lambda timing out - Stack Overflow
The default value for timeout in Lambda is 3 seconds = 3000 microseconds. Go to Advanced settings and add ...
Read more >
aws lambda read csv file from s3 python
About AWS Lambda 2 To read the file from s3 we will be using boto3: Lambda Gist Now when we read the file...
Read more >
Python, Boto3, and AWS S3: Demystified - Real Python
By the end of this tutorial, you'll: Be confident working with buckets and objects directly from your Python scripts; Know how to avoid...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found