use-cases/aws-lambda-redshift-event-driven-etl/LambdaRedshiftDataApiETL.py [60:93]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    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"]
    done = False
    while not done:
        time.sleep(1)
        status = status_check(client, query_id)
        if status in ("STARTED", "FAILED", "FINISHED"):
            print("status is: {}".format(status))
            break
    return query_id

def status_check(client, query_id):
    desc = client.describe_statement(Id=query_id)
    status = desc["Status"]
    if status == "FAILED":
        raise Exception('SQL query failed:' + query_id + ": " + desc["Error"])
    return status.strip('"')

def notify(sns_topic_arn, subject, body):
    subject = ("".join(ch for ch in subject if unicodedata.category(ch)[0] != "C"))[0:99]
    body = str(body)
    sns_client = boto3.client('sns')
    response = sns_client.publish(
        TargetArn=sns_topic_arn,
        Message=json.dumps({'default': json.dumps("{}"),
                            'sms': subject,
                            'email': body}),
        Subject=subject,
        MessageStructure='json'
    )
    return "message sent"
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



use-cases/aws-lambda-redshift-event-driven-etl/event-driven-redshift-pipeline.yaml [225:259]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
              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"]
              done = False
              while not done:
                  time.sleep(1)
                  status = status_check(client, query_id)
                  if status in ("STARTED", "FAILED", "FINISHED"):
                      print("status is: {}".format(status))
                      break
              return query_id

          def status_check(client, query_id):
              desc = client.describe_statement(Id=query_id)
              status = desc["Status"]
              if status == "FAILED":
                  raise Exception('SQL query failed:' + query_id + ": " + desc["Error"])
              return status.strip('"')

          def notify(sns_topic_arn, subject, body):
              subject = ("".join(ch for ch in subject if unicodedata.category(ch)[0] != "C"))[0:99]
              body = str(body)
              sns_client = boto3.client('sns')
              response = sns_client.publish(
                  TargetArn=sns_topic_arn,
                  Message=json.dumps({'default': json.dumps("{}"),
                                      'sms': subject,
                                      'email': body}),
                  Subject=subject,
                  MessageStructure='json'
              )
              return "message sent"
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



