Skip to content

Commit 87fda8b

Browse files
committed
fixing ResourceNotFoundException bug (in progress)
1 parent fe81294 commit 87fda8b

File tree

1 file changed

+16
-7
lines changed
  • aws_sra_examples/solutions/genai/bedrock_org/lambda/src

1 file changed

+16
-7
lines changed

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,14 @@ class sra_lambda:
5555
raise ValueError("Unexpected error executing Lambda function. Review CloudWatch logs for details.") from None
5656

5757
def find_lambda_function(self, function_name):
58-
"""Find Lambda Function."""
58+
"""Find Lambda Function.
59+
60+
Args:
61+
function_name: Lambda function name
62+
63+
Returns:
64+
Lambda function details if found, else None
65+
"""
5966
try:
6067
response = self.LAMBDA_CLIENT.get_function(FunctionName=function_name)
6168
return response
@@ -107,7 +114,6 @@ def create_lambda_function(self, code_zip_file, role_arn, function_name, handler
107114
else:
108115
self.LOGGER.info(f"Error deploying Lambda function: {error}")
109116
break
110-
# txt_response.insert(tk.END, f"Error deploying Lambda: {e}\n")
111117
try:
112118
retries = 0
113119
while retries < max_retries:
@@ -118,11 +124,14 @@ def create_lambda_function(self, code_zip_file, role_arn, function_name, handler
118124
# TODO(liamschn): need to add a maximum retry mechanism here
119125
retries += 1
120126
sleep(5)
121-
except Exception as e:
122-
self.LOGGER.info(f"Error getting Lambda function: {e}")
123-
124-
# except ClientError as e:
125-
# self.LOGGER.error(e)
127+
# TODO(liamschn): fix bug for ResourceNotFoundException found while working on least privilege access on role (in progress)
128+
except ClientError as e:
129+
if e.response["Error"]["Code"] == "ResourceNotFoundException":
130+
self.LOGGER.info(f"Lambda function {function_name} not found. Retrying...")
131+
sleep(5)
132+
else:
133+
self.LOGGER.info(f"Error getting Lambda function: {e}")
134+
raise ValueError(f"Error getting Lambda function: {e}") from None
126135
return get_response
127136

128137
def get_permissions(self, function_name):

0 commit comments

Comments
 (0)