def run_sql()

in use-cases/lambda-chaining-with-redshift-data-api/scripts/LambdaRedshiftDataApiUnload.py [0:0]


def run_sql(client, sql_text, redshift_database, redshift_user, redshift_cluster_id, with_event=True):
        MAX_WAIT_CYCLES = 20
        attempts = 0
        print("Executing: {}".format(sql_text))
        res = client.execute_statement(Database=redshift_database, DbUser=redshift_user, Sql=sql_text,
                                       ClusterIdentifier=redshift_cluster_id, WithEvent=with_event)
        print(res)
        query_id = res["Id"]

        while attempts < MAX_WAIT_CYCLES:
            attempts += 1
            time.sleep(1)
            status = status_check(client, query_id)
            if status in ("STARTED", "FAILED", "FINISHED"):
                print("status is: {}".format(status))
                break
        return query_id