Python boto3 upload failing with 403 on genesys cloud analytics export

Dealing with a very strange bug here with my daily analytics export pipeline. i have a python script that runs via cron in london timezone (02:00 gmt) to pull historical queue metrics from genesys cloud and dump them into s3. the logic is straightforward: authenticate, fetch the data via the /api/v2/analytics/queues/summary endpoint, transform the json, and upload using boto3.

the issue is intermittent. about 30% of the time, the upload succeeds. the other 70%, i get a botocore.exceptions.clienterror with status code 403 forbidden. the error message says “access denied”. i have verified that the aws credentials are correct and the iam role has s3:putobject permissions. i even tested the bucket with a simple put command and it works fine.

here is the relevant snippet:

import boto3
import requests

# fetch data
data = requests.get(gc_endpoint, headers={'Authorization': f'Bearer {token}'}).json()

# upload
s3_client = boto3.client('s3', region_name='eu-west-2')
try:
 s3_client.put_object(
 bucket='my-gc-exports',
 key=f'daily/queue_summary_{date}.json',
 body=json.dumps(data),
 content_type='application/json'
 )
except clienterror as e:
 print(f"upload failed: {e.response['error']['message']}")

the weird part is that the genesys api call always succeeds. it’s only the s3 upload that fails. i have added retries using botocore’s retry config but it still fails after max retries. could this be related to how the python sdk handles concurrent requests if the script is part of a larger orchestration? or is there something specific about the content length or headers i need to set? any ideas on debugging this 403?