This code is missing the important part of making describe_statement request to actually see the results of your statement execution.
Thank you for your comment. We'll review and update the Knowledge Center article as needed.
I am able to run the lambda against a serverless redshift cluster. The execute statement command works, but I am not able to see the returned result. result = client_redshift.execute_statement(Database= 'dev', SecretArn= secret_arn, Sql= query_str, ClusterIdentifier= cluster_id)
I am running Boto3 version 1.24.65
Logging the results end up blank. With this statement "logger.info('response', response)" I see this in CloudWatch:
[INFO] 2023-05-10T03:51:56.094Z a01a4549-5dc6-4ead-8060-c004b331f6ed response
The response object is never logged. And when trying to convert "result" to string with str(result) gives the following error:
[ERROR] TypeError: not all arguments converted during string formatting
But when I check the cluster via the AWS console, I see the new table was created. What needs to be done to be able to see the result of the query execution?
Thank you for your comment. We'll review and update the Knowledge Center article as needed.
As mentioned you'd need something to get the result of the execute command. I have a snippet below that I did, but you also have to import the time library as the time it takes the command to run can vary:
statement_id = result['Id']
describe_statement = client_redshift.describe_statement (
Id = statement_id
)
while True:
describe_statement = client_redshift.describe_statement (Id = statement_id)
if (describe_statement["Status"] == "FINISHED"):
print("Query Status - " + describe_statement["Status"])
break;
else:
print("Query Status - " + describe_statement["Status"])
time.sleep(2)
statement_result = client_redshift.get_statement_result(
Id = statement_id
)
You can then take statement_result and pull out information you may need. For instance if you were running a SELECT query, you could see that by calling/printing statement_result["Records"]
Thank you for your comment. We'll review and update the Knowledge Center article as needed.
Relevant content
- Accepted Answerasked 4 years ago
- Accepted Answerasked 3 years ago
- asked 2 years ago
- Accepted Answerasked 2 years ago
- asked a year ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 5 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago