Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CloudFormation: a way to define an ACTIVATED scheduled Glue job trigger

I'm using CloudFormation to define a SCHEDULED Glue job trigger according to the official documentation:

ParquetJobTrigger:
  Type: 'AWS::Glue::Trigger'
  Properties:
    Name: !Sub "${Prefix}_csv_to_parquet_job_trigger_${StageName}"
    Type: SCHEDULED
    Schedule: cron(0 0/1 * * ? *)
    Actions:
      - JobName: !Ref ParquetJob
        Arguments:
          "--job-bookmark-option": "job-bookmark-enable"

It works like a charm except one thing. It defines a job trigger that has a status CREATED and I have to manually enable it:

enter image description here

Is there a way to define an activated scheduled trigger alone via CloudFormation?

like image 614
Andrey Cheptsov Avatar asked Feb 05 '18 08:02

Andrey Cheptsov


2 Answers

For anyone new looking, this can be achieved now by using the StartOnCreation property for new triggers.

UEDDBJobTrigger:
  Type: AWS::Glue::Trigger
  Properties:
    Name: Foo
    Description: Scheduled trigger
    Type: SCHEDULED
    Schedule: "cron(0 10 ? * MON-FRI *)"
    StartOnCreation: true
    Actions: 
      - JobName: !Ref TestJob
like image 67
Gregory Posey Avatar answered Nov 04 '22 21:11

Gregory Posey


Had the same issue and opened up a ticket with AWS. Looks like they currently do not have the feature but are looking to address in their next feature release. Below is their response:

Thank you for contacting AWS premium support. It was a pleasure speaking with you today. I am writing back to followup on our conversation. I was able to get in touch with members of the Glue team and the Cloud Formation team following are my findings:

1) It looks like there isn't away to enable the Glue trigger using the resource namespace: AWS::Glue::Trigger

2) The scheduled jobs should retry on the next scheduled time if the first time it does so fails

3) As a work around to the above, what you could do is have the scheduled actions trigger a certain length of time after the stack is created in order for you to manually enable the trigger through the web console.

4) As discussed during our call, it looks like a Lambda function could in fact be feasible. In this case you can have the Lambda Function depend on the Trigger resource and then make the API call start-trigger (https://docs.aws.amazon.com/cli/latest/reference/glue/start-trigger.html) using the lambda function to enable the trigger. These actions should occur in time for the scheduled jobs to be triggered.

Following are some useful references for Lambda and Cloud Formation: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/walkthrough-custom-resources-lambda-lookup-amiids.html https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html

like image 33
JustinJ Avatar answered Nov 04 '22 22:11

JustinJ