Skip to content

Commit 0e0a486

Browse files
committed
rearranging code for retries
1 parent a4a628e commit 0e0a486

File tree

1 file changed

+14
-12
lines changed
  • aws_sra_examples/solutions/genai/bedrock_org/lambda/src

1 file changed

+14
-12
lines changed

aws_sra_examples/solutions/genai/bedrock_org/lambda/src/sra_lambda.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,26 +115,28 @@ def create_lambda_function(self, code_zip_file, role_arn, function_name, handler
115115
else:
116116
self.LOGGER.info(f"Error deploying Lambda function: {error}")
117117
break
118-
try:
119-
retries = 0
120-
while retries < max_retries:
118+
retries = 0
119+
while retries < max_retries:
120+
try:
121121
self.LOGGER.info(f"Search for function attempt {retries+1} of {max_retries}...")
122122
get_response = self.LAMBDA_CLIENT.get_function(FunctionName=function_name)
123123
if get_response["Configuration"]["State"] == "Active":
124124
self.LOGGER.info(f"Lambda function {function_name} is now active")
125125
break
126126
# TODO(liamschn): need to add a maximum retry mechanism here
127+
else:
128+
self.LOGGER.info(f"{function_name} lambda function state is {get_response["Configuration"]["State"]}. Waiting to retry...")
127129
retries += 1
128130
sleep(5)
129-
# TODO(liamschn): fix bug for ResourceNotFoundException found while working on least privilege access on role (in progress)
130-
except ClientError as e:
131-
if e.response["Error"]["Code"] == "ResourceNotFoundException":
132-
self.LOGGER.info(f"Lambda function {function_name} not found. Retrying...")
133-
retries += 1
134-
sleep(5)
135-
else:
136-
self.LOGGER.info(f"Error getting Lambda function: {e}")
137-
raise ValueError(f"Error getting Lambda function: {e}") from None
131+
# TODO(liamschn): fix bug for ResourceNotFoundException found while working on least privilege access on role (in progress)
132+
except ClientError as e:
133+
if e.response["Error"]["Code"] == "ResourceNotFoundException":
134+
self.LOGGER.info(f"Lambda function {function_name} not found. Retrying...")
135+
retries += 1
136+
sleep(5)
137+
else:
138+
self.LOGGER.info(f"Error getting Lambda function: {e}")
139+
raise ValueError(f"Error getting Lambda function: {e}") from None
138140
return get_response
139141

140142
def get_permissions(self, function_name):

0 commit comments

Comments
 (0)