Skip to content

Instantly share code, notes, and snippets.

@davidkelley
Last active September 6, 2015 14:42
Show Gist options
  • Save davidkelley/6fb9a1abed8eb8c6acf1 to your computer and use it in GitHub Desktop.
Save davidkelley/6fb9a1abed8eb8c6acf1 to your computer and use it in GitHub Desktop.
AWS Cloudformation integrated Task Scheduler

DynamoDB Table

| string:Hash | string | string | string | string | string | string | |------|---|---|---|---|---|---|---| | Id | StartTime | EndTime | Recurrence | Type | Name | Message |

Scheduler Cloudformation

  1. Creates DynamoDB table: scheduler_table
  2. Creates Lambda function to act as Cloudformation custom resource
  3. Adds an ECS container instance that polls scheduler_table to a cluster

Task Lifecycle

  1. The polling container is started with a polling option that defines the polling interval of DynamoDB, like --interval 60.
  2. Upon polling, all tasks are retrieved and their periodicity examined.
  3. If a task is ready to be triggered, the message is sent to the SQS queue.
  • If a task will be triggered before the next polling interval occurs, the main thread is forked and at the correct time, the task is triggered and the fork merged.

Task Defining

{
  "Resources" : {
    ...
    
    "Task": {
      "Type": "Custom::Tasker",
      "Properties": {
        "ServiceToken": { "Ref" : "TaskerArn" },
        "Definitions" : [
          {
            "Id" : "EMEARegionHarvest",
            "Type" : "SQS",
            "Name" : { "Fn::GetAtt" : ["TaskQueue", "QueueName"] },
            "Recurrence" : "30 */6 * * *",
            "Message" : {
              "$" : ["rake harvest[emea]"]
            }
          },
          {
            "Id" : "ScheduledServiceScaler",
            "Type" : "SNS",
            "Name" : { "Fn::GetAtt" : ["ScalerTopic", "TopicName"] },
            "StartTime" : "2015-10-01T00:00:00Z",
            "EndTime" : "2015-10-02T00:00:00Z",
            "Recurrence" : "*/10 * * * *",
            "Message" : {
              ...
            }
          }
        ]
      }
    },

    "ScalerTopic" : {
      "Type" : "AWS::SNS::Topic"
    },

    "TaskQueue" : {
      "Type" : "AWS::SQS::Queue"
    },
    
    ...
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment