Rudresh Ajgaonkar
Rudresh Ajgaonkar

Reputation: 790

AWS Glue create Triggers via API

I have a table which contains few schedules for various jobs.

I want to process the records and create Triggers via AWS Glue API.

http://docs.aws.amazon.com/glue/latest/dg/aws-glue-api.html

The above link shows the documentation go for AWS Glue.

Is there anyone who can provide a code snippet on how to use the API? I have searched for long enough on the net and havent found any documentation that provides a code snippet!

I am looking for code snippet for the following API CALL. CreateTrigger Action (Python: create_trigger)

Any help would be great.

Upvotes: 3

Views: 2125

Answers (2)

hoaxz
hoaxz

Reputation: 751

This is a quick snipped of how to create a schedule based trigger. Notice how you can have multiple jobs (soft limit is 10 per trigger) ran by the trigger:

# Initialize glue client
import boto3
client = boto3.client('glue')

# Create trigger 'body'
trigger = dict(
    Name='trigger_name',
    Description='My trigger description',
    Type='SCHEDULED',
    Actions=[
        dict(JobName='first_job_name_to_be_triggered'),
        dict(JobName='second_job_name_to_be_triggered')
    ],
    Schedule='cron(0 8 * * ? *)' #Every day at 8am UTC
)

# Create the trigger
client.create_trigger(**trigger)

# After trigger is created, you want to activate it
client.start_trigger(Name=trigger['Name'])

If you wanted the trigger to run the job after some other jobs succeed you would define the trigger like this:

trigger = dict(
    Name='trigger_name',
    Description='My trigger description',
    Type='CONDITIONAL',
    Actions=[dict(JobName='job_name_to_be_triggered')],
    Predicate=dict(
        Logical='AND',
        Conditions=[
            dict(
                JobName='first_job_required_to_succeed',
                LogicalOperator='EQUALS',
                State='SUCCEEDED'
            ),
            dict(
                JobName='second_job_required_to_succeed',
                LogicalOperator='EQUALS',
                State='SUCCEEDED'
            ),
        ]
    )
)  

Hope this helps

Upvotes: 4

Rudresh Ajgaonkar
Rudresh Ajgaonkar

Reputation: 790

http://boto3.readthedocs.io/en/latest/reference/services/glue.html#id75

This is what i was looking for. BOTO3 is the library used to call the api and has nice documentation for the same

Upvotes: 0

Related Questions