Building a daily analytics export job that pulls interaction data from Genesys Cloud via the Python SDK and pushes it to S3 using boto3. The flow works fine for small date ranges, but when we try to export a full month of data, the S3 upload times out. The OTel spans show the Genesys Cloud API calls completing successfully, but the boto3 upload_file call hangs and eventually throws a botocore.exceptions.ConnectionError: Connection closed by server.
Here’s the relevant snippet:
import boto3
from purecloudplatformclientv2 import AnalyticsApi, PureCloudConfiguration
# Setup GC API client
config = PureCloudConfiguration()
config.host = 'https://api.mypurecloud.com'
config.access_token = get_token() # Handles OAuth refresh
analytics_api = AnalyticsApi(configuration=config)
# Fetch data
response = analytics_api.get_analytics_interactions_query(
body={'interval': 'P1M', 'metrics': ['duration']}
)
# Upload to S3
s3 = boto3.client('s3', region_name='ap-southeast-1')
try:
s3.upload_fileobj(
io.BytesIO(response.body),
'my-analytics-bucket',
f'data/{date}.json'
)
except Exception as e:
logger.error(f"Upload failed: {e}")
The issue seems to be that response.body is a large JSON string, and upload_fileobj expects a file-like object. I’m wrapping it in io.BytesIO, but the upload still fails with a connection reset. I’ve tried increasing the ConnectTimeout and ReadTimeout in the boto3 config, but it doesn’t help. The OTel trace shows the span for the upload lasting over 30 seconds before failing.
Is there a better way to stream the response from the Genesys Cloud API directly to S3 without loading it all into memory? Or am I missing something in the boto3 configuration? The data size is around 50MB for a month. We’re using Python 3.9 and the latest purecloudplatformclientv2 SDK.