I use boto3 to work with S3. If my application cannot reach S3 due to a network problem, the connection will hang until it ends. I would like to set a lower connection timeout. I met this PR for a botocore that allows you to set a timeout:
$ sudo iptables -A OUTPUT -p tcp --dport 443 -j DROP
from botocore.client import Config
import boto3
config = Config(connect_timeout=5, read_timeout=5)
s3 = boto3.client('s3', config=config)
s3.head_bucket(Bucket='my-s3-bucket')
This calls ConnectTimeout, but there is still too much to fix the error:
ConnectTimeout: HTTPSConnectionPool(host='my-s3-bucket.s3.amazonaws.com', port=443): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<botocore.awsrequest.AWSHTTPSConnection object at 0x2ad5dd0>, 'Connection to my-s3-bucket.s3.amazonaws.com timed out. (connect timeout=5)'))
Setting connection and read timeouts does not affect how quickly the connection responds.
source
share