Skip to content

Commit 2bf178d

Browse files
authored
Add additional retry to prevent throttling (#288)
1 parent e989b90 commit 2bf178d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

data-collection/deploy/module-health-events.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ Resources:
143143
from datetime import date, datetime, timedelta, timezone
144144
145145
import boto3
146+
from botocore.config import Config
146147
147148
logger = logging.getLogger()
148149
logger.setLevel(getattr(logging, os.environ.get('LOG_LEVEL', 'INFO').upper(), logging.INFO))
@@ -156,6 +157,9 @@ Resources:
156157
LOOKBACK = int(os.environ['LOOKBACK'])
157158
DETAIL_SM_ARN = os.environ['DETAIL_SM_ARN']
158159
TMP_FILE = "/tmp/data.json"
160+
MAX_RETRIES = int(os.environ.get('MAX_RETRIES', "10"))
161+
162+
config = Config(retries={"max_attempts": MAX_RETRIES, "mode": "adaptive"})
159163
160164
mapping = {
161165
'payer_account_id': 'payer_account_id',
@@ -341,6 +345,7 @@ Resources:
341345
)['Credentials']
342346
health_client = boto3.client(
343347
'health',
348+
config=config,
344349
region_name=region,
345350
aws_access_key_id=creds['AccessKeyId'],
346351
aws_secret_access_key=creds['SecretAccessKey'],
@@ -415,7 +420,7 @@ Resources:
415420
if count > 0:
416421
rand = uuid.uuid4()
417422
key = ingestion_time.strftime(f"{PREFIX}/{PREFIX}-detail-data/payer_id={account_id}/year=%Y/month=%m/day=%d/%Y-%m-%d-%H-%M-%S-{rand}.json")
418-
boto3.client('s3').upload_file(TMP_FILE, BUCKET_NAME, key)
423+
boto3.client('s3', config=config).upload_file(TMP_FILE, BUCKET_NAME, key)
419424
logger.info(f'Uploaded {count} summary records to s3://{BUCKET_NAME}/{key}')
420425
return {"status":"200","Recorded":f'"{count}"'}
421426
Handler: "index.lambda_handler"

0 commit comments

Comments
 (0)