0

I'm trying to upload files to S3, but if the file takes too long to upload I'd like a Timeout exception to be raised.

I've tried using the Config object from botocore to set a timeout of 1 second, but the upload process spends > 5 seconds uploading. I would expect an exception to be raised after 1 second.

import requests
from boto3 import Session
from botocore.config import Config

url = 'https://www.hq.nasa.gov/alsj/a17/A17_FlightPlan.pdf' # a large pdf
response = requests.get(url)

session = Session()
config = Config(connect_timeout=1, read_timeout=1, retries={'max_attempts': 0})
client = session.client('s3', config=config)

client.put_object(Body=response.content, Bucket='test', Key='test.pdf')

Does boto3 have a configuration option that allows me to prevent long uploads?

bgordon
  • 109
  • 1
  • 12
  • Possible duplicate of https://stackoverflow.com/questions/2281850/timeout-function-if-it-takes-too-long-to-finish – hephalump Aug 28 '19 at 10:59
  • @hephalump I'm aware that I can timeout functions using signal. I'm interested to see whether boto3 has an inbuilt solution, similar to how the requests library has a timeout argument (e.g. `requests.get(url, timeout=5)` – bgordon Aug 28 '19 at 11:06

0 Answers0