Considering an AWS lambda written in Python that uses boto3 as client to AWS Redshift service.
Considering the following example:
import boto3
import moto
def lambda_handler(event, context):
session = boto3.session.Session()
redshift_data_service = session.client(
service_name='redshift-data',
region_name='a_region',
)
query_id = redshift_data_service.execute_statement(
sql="insert into XYZ VALUES..."
)
while True: // With timeout
job_state = redshift_data_service.describe_statement(Id=query_id)
if job_state["Status"] == "FAILED"
break
...
@moto.redshiftdata
def test_insert_sql_insert():
# MOCK describe_statement invocations here
lambda_handler(...)
redshift_data_service = boto3.client("redshift-data", region_name='a_region')
# Assert execute_statement
I had to use a loop to check the state of the insert statement and retrieve the error. As far as I understood, to retrieve the error I need to do pooling using describe_statement
as described here -> https://github.com/awslabs/amazon-redshift-utils/blob/master/src/SimpleReplay/helper/aws_service.py
Using Moto python dependency to mock redshift-data
(similar to the example above), how can I give in advance data regarding describe statements?
Is there a way to mock all the describe_statement retrieved by execute_statement? The idea is testing the variuos state of the desscribe function considering the description of the statement, when it's "STARTED", "FAILED" and "FINISHED"