Skip to content
This repository was archived by the owner on Mar 13, 2020. It is now read-only.

Commit 0cbb5f9

Browse files
committed
add error handling to AWSLambdaDataSource
1 parent 2efde69 commit 0cbb5f9

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

rdl/data_sources/AWSLambdaDataSource.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def __get_table_info(self, table_config, last_known_sync_version):
8686
"Command": "GetTableInfo",
8787
"TenantId": int(self.connection_data["tenant"]),
8888
"Table": {"Schema": table_config["schema"], "Name": table_config["name"]},
89-
"CommandPayload": {"lastSyncVersion": last_known_sync_version},
89+
"CommandPayload": {"LastSyncVersion": last_known_sync_version},
9090
}
9191

9292
result = self.__invoke_lambda(pay_load)
@@ -134,13 +134,32 @@ def __get_data_frame(self, data: [[]], column_names: []):
134134
def __invoke_lambda(self, pay_load):
135135
self.logger.debug('\nRequest being sent to Lambda:')
136136
self.logger.debug(pay_load)
137+
137138
lambda_response = self.aws_lambda_client.invoke(
138139
FunctionName=self.connection_data["function"],
139140
InvocationType="RequestResponse",
140141
LogType="None", # |'Tail', Set to Tail to include the execution log in the response
141142
Payload=json.dumps(pay_load).encode(),
142143
)
143-
result = json.loads(lambda_response['Payload'].read()) # .decode()
144-
self.logger.debug('\nResponse received from Lambda:\n')
145-
self.logger.debug(result)
146-
return result
144+
145+
response_status_code = int(lambda_response['StatusCode'])
146+
response_function_error = lambda_response.get("FunctionError")
147+
self.logger.debug('\nResponse received from Lambda:')
148+
self.logger.debug(f'Response - StatusCode = "{response_status_code}"')
149+
self.logger.debug(f'Response - FunctionError = "{response_function_error}"')
150+
151+
response_payload = json.loads(lambda_response['Payload'].read())
152+
153+
if response_status_code != 200 or response_function_error:
154+
self.logger.error(F'Error in response from aws lambda {self.connection_data["function"]}')
155+
self.logger.error(f'Response - Status Code = {response_status_code}')
156+
self.logger.error(f'Response - Error Function = {response_function_error}')
157+
self.logger.error(f'Response - Error Details:')
158+
# the below is risky as it may contain actual data if this line is reached in case of a successful result
159+
# however, the same Payload field is used to return actual error details in case of real errors
160+
# i.e. StatusCode is 200 (since AWS could invoke the lambda)
161+
# BUT the lambda barfed with an error and therefore the FunctionError would not be None
162+
self.logger.error(response_payload)
163+
raise Exception('Error received when invoking AWS Lambda. See logs for further details.')
164+
165+
return response_payload

0 commit comments

Comments
 (0)