I have a stored procedure in Redshift that I want to call using my Lambda function. I'm using boto3 redshift-data API to do this. My Lambda looks something like this:
import boto3
client = boto3.client('redshift-data')
def execute_query(Query):
response = client.execute_statement(Database= DBname,DbUser= username,Sql=Query,ClusterIdentifier= ClusterID)
return response["Id"]
def lambda_handler(event, context):
Query = "CALL {PROCEDURE}({arg1},{arg2},{arg3})".format(**event)
id = execute_query(Query)
return id
Please note that the stored procedure is quiet lengthy and will take some time to complete as there are a lot of records in Redshift. What I expected from boto3 redshift-data API is that, it'll return the a response back to the Lambda function including a QueryID as soon as it submits the job, and would not wait for the procedure to complete. But this is not happening. The Lambda doesn't get the control back and therefore times-out.
I used StepFunctions to orchestrate this job. The state machine included the above Lambda- to execute a procedure call-, another Lambda that checks the status of the query and a Wait state that will be repeatedly called until the query is procedure is finished.
Can someone please help me in understanding what I'm doing wrong and why boto3 not returning the response immediately?
I tried to look into the logs, checked things in Redshift but I can't find anything.