Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Latest commit

 

History

History
358 lines (318 loc) · 11.7 KB

aws-resource-glue-trigger.md

File metadata and controls

358 lines (318 loc) · 11.7 KB

AWS::Glue::Trigger

The AWS::Glue::Trigger resource specifies triggers that run AWS Glue jobs. For more information, see Triggering Jobs in AWS Glue and Trigger Structure in the AWS Glue Developer Guide.

Syntax

To declare this entity in your AWS CloudFormation template, use the following syntax:

JSON

{
  "Type" : "AWS::Glue::Trigger",
  "Properties" : {
      "[Actions](#cfn-glue-trigger-actions)" : [ [Action](aws-properties-glue-trigger-action.md), ... ],
      "[Description](#cfn-glue-trigger-description)" : String,
      "[Name](#cfn-glue-trigger-name)" : String,
      "[Predicate](#cfn-glue-trigger-predicate)" : [Predicate](aws-properties-glue-trigger-predicate.md),
      "[Schedule](#cfn-glue-trigger-schedule)" : String,
      "[StartOnCreation](#cfn-glue-trigger-startoncreation)" : Boolean,
      "[Tags](#cfn-glue-trigger-tags)" : Json,
      "[Type](#cfn-glue-trigger-type)" : String,
      "[WorkflowName](#cfn-glue-trigger-workflowname)" : String
    }
}

YAML

Type: AWS::Glue::Trigger
Properties: 
  [Actions](#cfn-glue-trigger-actions): 
    - [Action](aws-properties-glue-trigger-action.md)
  [Description](#cfn-glue-trigger-description): String
  [Name](#cfn-glue-trigger-name): String
  [Predicate](#cfn-glue-trigger-predicate): 
    [Predicate](aws-properties-glue-trigger-predicate.md)
  [Schedule](#cfn-glue-trigger-schedule): String
  [StartOnCreation](#cfn-glue-trigger-startoncreation): Boolean
  [Tags](#cfn-glue-trigger-tags): Json
  [Type](#cfn-glue-trigger-type): String
  [WorkflowName](#cfn-glue-trigger-workflowname): String

Properties

Actions The actions initiated by this trigger.
Required: Yes
Type: List of Action
Update requires: No interruption

Description A description of this trigger.
Required: No
Type: String
Update requires: No interruption

Name The name of the trigger.
Required: No
Type: String
Update requires: Replacement

Predicate The predicate of this trigger, which defines when it will fire.
Required: No
Type: Predicate
Update requires: No interruption

Schedule A cron expression used to specify the schedule. For more information, see Time-Based Schedules for Jobs and Crawlers in the AWS Glue Developer Guide. For example, to run something every day at 12:15 UTC, specify cron(15 12 * * ? *).
Required: No
Type: String
Update requires: No interruption

StartOnCreation Set to true to start SCHEDULED and CONDITIONAL triggers when created. True is not supported for ON_DEMAND triggers.
Required: No
Type: Boolean
Update requires: No interruption

Tags The tags to use with this trigger.
Required: No
Type: Json
Update requires: No interruption

Type The type of trigger that this is.
Required: Yes
Type: String
Update requires: No interruption

WorkflowName The name of the workflow associated with the trigger.
Required: No
Type: String
Update requires: Replacement

Return Values

Ref

When you pass the logical ID of this resource to the intrinsic Ref function, Ref returns the trigger name.

For more information about using the Ref function, see Ref.

Examples

On-Demand Trigger

The following example creates an on-demand trigger that triggers one job.

JSON

{
  "Resources": {
    "OnDemandJobTrigger": {
      "Type": "AWS::Glue::Trigger",
      "Properties": {
        "Type": "ON_DEMAND",
        "Description": "DESCRIPTION_ON_DEMAND",
        "Actions": [
          {
            "JobName": "prod-job2"
          }
        ],
        "Name": "prod-trigger1-ondemand"
      }
    }
  }
}

YAML

Resources:
  OnDemandJobTrigger:
    Type: AWS::Glue::Trigger
    Properties:
      Type: ON_DEMAND
      Description: DESCRIPTION_ON_DEMAND
      Actions:
        - JobName: prod-job2
      Name: prod-trigger1-ondemand

Scheduled Trigger

The following example creates a scheduled trigger that runs every two hours and triggers two jobs. Note that it declares an argument for prod-job3.

JSON

{
  "Resources": {
    "ScheduledJobTrigger": {
      "Type": "AWS::Glue::Trigger",
      "Properties": {
        "Type": "SCHEDULED",
        "Description": "DESCRIPTION_SCHEDULED",
        "Schedule": "cron(0 */2 * * ? *)",
        "Actions": [
          {
            "JobName": "prod-job2"
          },
          {
            "JobName": "prod-job3",
            "Arguments": {
              "--job-bookmark-option": "job-bookmark-enable"
            }
          }
        ],
        "Name": "prod-trigger1-scheduled"
      }
    }
  }
}

YAML

Resources:
  ScheduledJobTrigger:
    Type: AWS::Glue::Trigger
    Properties:
      Type: SCHEDULED
      Description: DESCRIPTION_SCHEDULED
      Schedule: cron(0 */2 * * ? *)
      Actions:
        - JobName: prod-job2
        - JobName: prod-job3
          Arguments:
            '--job-bookmark-option': job-bookmark-enable
      Name: prod-trigger1-scheduled

Conditional Trigger

The following example creates a conditional trigger that starts a job based on the successful completion of the job run.

JSON

{
  "Description": "AWS Glue Trigger Test",
  "Resources": {
    "MyJobTriggerRole": {
      "Type": "AWS::IAM::Role",
      "Properties": {
        "AssumeRolePolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Effect": "Allow",
              "Principal": {
                "Service": [
                  "glue.amazonaws.com"
                ]
              },
              "Action": [
                "sts:AssumeRole"
              ]
            }
          ]
        },
        "Path": "/",
        "Policies": [
          {
            "PolicyName": "root",
            "PolicyDocument": {
              "Version": "2012-10-17",
              "Statement": [
                {
                  "Effect": "Allow",
                  "Action": "*",
                  "Resource": "*"
                }
              ]
            }
          }
        ]
      }
    },
    "MyJob": {
      "Type": "AWS::Glue::Job",
      "Properties": {
        "Name": "MyJobTriggerJob",
        "LogUri": "wikiData",
        "Role": {
          "Ref": "MyJobTriggerRole"
        },
        "Command": {
          "Name": "glueetl",
          "ScriptLocation": "s3://testdata-bucket/s3-target/create-delete-job-xtf-ETL-s3-json-to-csv.py"
        },
        "DefaultArguments": {
          "--job-bookmark-option": "job-bookmark-enable"
        },
        "MaxRetries": 0
      }
    },
    "MyJobTrigger": {
      "Type": "AWS::Glue::Trigger",
      "Properties": {
        "Name": "MyJobTrigger",
        "Type": "CONDITIONAL",
        "Description": "Description for a conditional job trigger",
        "Actions": [
          {
            "JobName": {
              "Ref": "MyJob"
            },
            "Arguments": {
              "--job-bookmark-option": "job-bookmark-enable"
            }
          }
        ],
        "Predicate": {
          "Conditions": [
            {
              "LogicalOperator": "EQUALS",
              "JobName": {
                "Ref": "MyJob"
              },
              "State": "SUCCEEDED"
            }
          ]
        }
      }
    }
  }
}

YAML

---
Description: "AWS Glue Trigger Test"
Resources:
  MyJobTriggerRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          -
            Effect: "Allow"
            Principal:
              Service:
                - "glue.amazonaws.com"
            Action:
              - "sts:AssumeRole"
      Path: "/"
      Policies:
        -
          PolicyName: "root"
          PolicyDocument:
            Version: "2012-10-17"
            Statement:
              -
                Effect: "Allow"
                Action: "*"
                Resource: "*"
  MyJob:
    Type: AWS::Glue::Job
    Properties:
      Name: "MyJobTriggerJob"
      LogUri: "wikiData"
      Role: !Ref MyJobTriggerRole
      Command:
        Name: "glueetl"
        ScriptLocation: "s3://testdata-bucket/s3-target/create-delete-job-xtf-ETL-s3-json-to-csv.py"
      DefaultArguments:
        "--job-bookmark-option": "job-bookmark-enable"
      MaxRetries: 0
  MyJobTrigger:
    Type: AWS::Glue::Trigger
    Properties:
      Name: "MyJobTrigger"
      Type: "CONDITIONAL"
      Description: "Description for a conditional job trigger"											
      Actions:
        - JobName: !Ref MyJob
          Arguments:
            "--job-bookmark-option": "job-bookmark-enable"
      Predicate:
        Conditions:
          - LogicalOperator: EQUALS
            JobName: !Ref MyJob
            State: SUCCEEDED