use-cases/aws-lambda-redshift-event-driven-etl/event-driven-redshift-pipeline.yaml [233:315]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                  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"
  RedshiftS3AccessForEventAppBucket:
    Type: 'AWS::IAM::ManagedPolicy'
    Properties:
      PolicyDocument:
        Version: '2012-10-17'
        Statement:
          - Sid: AllowAllUsersToGetS3Objects
            Effect: Allow
            Action:
              - 's3:GetObject'
            Resource: 'arn:aws:s3:::event-driven-app-with-lambda-redshift/*'
          - Sid: AllowAllUsersToListS3Bucket
            Effect: Allow
            Action:
              - 's3:ListBucket'
            Resource: 'arn:aws:s3:::event-driven-app-with-lambda-redshift'
      Roles: [!Ref RedshiftIAMRoleName]
  SetupRedshiftObjectsLambdaRole:
    DependsOn: LambdaRedshiftDataApiETL
    Type: AWS::IAM::Role
    Properties:
      Description : IAM Role for lambda to invoke LambdaRedshiftDataApiETL lambda function
      AssumeRolePolicyDocument:
          Version: 2012-10-17
          Statement:
            -
              Effect: Allow
              Principal:
                Service:
                  - lambda.amazonaws.com
              Action:
                - sts:AssumeRole
      Path: /
      Policies:
          -
            PolicyName: LambdaInvokePolicy
            PolicyDocument :
              Version: 2012-10-17
              Statement:
                -
                  Effect: "Allow"
                  Action:
                  - lambda:InvokeFunction
                  - lambda:InvokeAsync
                  Resource: !GetAtt [LambdaRedshiftDataApiETL, Arn]
                -
                  Effect: "Allow"
                  Action:
                  - logs:CreateLogGroup
                  - logs:CreateLogStream
                  - logs:PutLogEvents
                  Resource: "*"
  LambdaSetupRedshiftObjects:
    Type: "AWS::Lambda::Function"
    DependsOn: SetupRedshiftObjectsLambdaRole
    Properties:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



use-cases/lambda-chaining-with-redshift-data-api/cloud_formation_template/lambda-chaining-with-redshift-data-api.yaml [267:347]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                  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"
  RedshiftS3AccessForEventAppBucket:
    Type: 'AWS::IAM::ManagedPolicy'
    Properties:
      PolicyDocument:
        Version: '2012-10-17'
        Statement:
          - Sid: AllowAllUsersToGetS3Objects
            Effect: Allow
            Action:
              - 's3:GetObject'
            Resource: 'arn:aws:s3:::event-driven-app-with-lambda-redshift/*'
          - Sid: AllowAllUsersToListS3Bucket
            Effect: Allow
            Action:
              - 's3:ListBucket'
            Resource: 'arn:aws:s3:::event-driven-app-with-lambda-redshift'
      Roles: [!Ref RedshiftIAMRoleName]
  SetupRedshiftObjectsLambdaRole:
    DependsOn: LambdaRedshiftDataApiETL
    Type: AWS::IAM::Role
    Properties:
      Description : IAM Role for lambda to invoke LambdaRedshiftDataApiETL lambda function
      AssumeRolePolicyDocument:
          Version: 2012-10-17
          Statement:
            -
              Effect: Allow
              Principal:
                Service:
                  - lambda.amazonaws.com
              Action:
                - sts:AssumeRole
      Path: /
      Policies:
          -
            PolicyName: LambdaInvokePolicy
            PolicyDocument :
              Version: 2012-10-17
              Statement:
                -
                  Effect: "Allow"
                  Action:
                  - lambda:InvokeFunction
                  - lambda:InvokeAsync
                  Resource: !GetAtt [LambdaRedshiftDataApiETL, Arn]
                -
                  Effect: "Allow"
                  Action:
                  - logs:CreateLogGroup
                  - logs:CreateLogStream
                  - logs:PutLogEvents
                  Resource: "*"
  LambdaSetupRedshiftObjects:
    Type: "AWS::Lambda::Function"
    DependsOn: SetupRedshiftObjectsLambdaRole
    Properties:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



