4

I'm using boto3 to load some file from an AWS S3 bucket. Which is working fine. However for my unittests i'm calling freeze_time and then the function returns the error: botocore.exceptions.ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden.

Is there a solution, which enables me to keep using freeze_time and which will retreive the file from S3?

The code works without @freeze_time("2019-01-30") and doesn't when added.

import boto3
from freezegun import freeze_time
import io

bucket = 'bucket'
key = 'key'

@freeze_time("2019-01-30")
def test_x():
    s3 = boto3.client('s3')
    f = io.BytesIO()
    s3.download_fileobj(bucket, key, f)

test_x()
Johannes
  • 41
  • 3

1 Answers1

2

No -- you can not use freeze_time. You'll need to find another approach.

AWS api calls require the times to agree "within reason" between client and server. A client saying January, when it's actually May, is not considered "reasonable". Per information on aws.amazon.com, the maximum allowed clock skew is 15 minutes.

For some SDKs, Amazon embeds an automatic clock skew correction. Which lets the calls complete, but may not give you the timing you expect.

Hal W
  • 186
  • 1
  • 9