RequestTimeTooSkewed: boto3 upload sometimes fails when run in thread

Viewed 101

I often want to upload files to Amazon S3 in the background. I'm using threads for this. Sometimes, but not always, this results in a RequestTimeTooSkewed error.

import threading
from pathlib import Path
import boto3

def upload_file_s3(
    local_path: Path,
    s3_path: Path,
    bucket: str,
) -> None:
    ACCESS_KEY = ""
    SECRET_KEY = ""
    client = boto3.client(
        "s3",
        aws_access_key_id=ACCESS_KEY,
        aws_secret_access_key=SECRET_KEY,
        region_name="eu-central-1",
        use_ssl=False,
        verify=False,
    )
    client.upload_file(str(local_path), bucket, str(s3_path))


local_path = Path('/tmp/testfile')
s3_path = Path('testfile')
bucket = 'my_bucket'

thread = threading.Thread(target=upload_file_s3, args=(local_path, s3_path, bucket))
thread.start()
botocore.exceptions.ClientError: An error occurred (RequestTimeTooSkewed) when calling the UploadPart operation: The difference between the request time and the current time is too large.
0 Answers
Related