Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into cwlogs-limits
Browse files Browse the repository at this point in the history
  • Loading branch information
BastLeblanc committed Aug 29, 2024
2 parents e4cb752 + 2f9234f commit 88af567
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions aws/cloudformation-templates/deployment-support.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ Resources:
Role: !GetAtt LoadDataLambdaRole.Arn
Runtime: python3.12
MemorySize: 128
Timeout: 120
Timeout: 600
VpcConfig:
SecurityGroupIds:
- !Ref LambdaVpcSecurityGroup
Expand All @@ -184,25 +184,35 @@ Resources:
from urllib.error import URLError
import logging
import cfnresponse
import time
import os
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def handler(event, context):
response_data = {}
response_status = cfnresponse.SUCCESS
max_retries = 15 # Maximum number of retries - should be less than the timeout
retries = 0
if event['RequestType'] in ['Create', 'Update']:
url = os.environ['ProductsServiceUrl']
request = Request(f"{url}/init", method='POST')
try:
with urlopen(request) as response:
logger.info(f"Product Service init method success: {response.read()}")
except URLError as e:
logger.error(f"Error calling product service init: {e.code} : {e.reason}")
response_status = cfnresponse.FAILED
response_data['Message'] = f"Resource {event['RequestType']} failed: {e}"
while retries < max_retries:
try:
with urlopen(request) as response:
logger.info(f"Product Service init method success: {response.read()}")
# exit while, success.
break
except URLError as e:
retries += 1
print(f"Request failed. Retrying in 30 seconds... (Attempt {retries}/{max_retries})")
print(f"Error: {e}")
time.sleep(30)
#
if retries >= max_retries:
logger.error(f"Error calling product service init: {e.code} : {e.reason}")
response_status = cfnresponse.FAILED
response_data['Message'] = f"Resource {event['RequestType']} failed: {e}"
cfnresponse.send(event, context, response_status, response_data)
Expand Down

0 comments on commit 88af567

Please sign in to comment.