CRON scheduled functions #147

tj opened this Issue Jan 25, 2016 · 11 comments


None yet

5 participants

tj commented Jan 25, 2016

Seems like they don't provide an API for this yet which is a little weird, hopefully that's coming:

kapilt commented Jan 26, 2016

there's sort of a usable shim for it in the cloud watch events service which allows cron spec invocation of target lambda function



@tj Ok, I've found a solution, checkout: johannesboyne@95d8383

svcc := cloudwatchevents.New(session.New())
svcl := lambda.New(session.New())

cronEvent := &Cron{
    Name:              "CronTestLambda",
    Description:       "Test",
    Expression:        "rate(5 minutes)",
    FunctionName:      "<function-name>",
    FunctionArn:       "arn:aws:lambda:us-west-2:<...>",
    CloudWatchService: svcc,
    LambdaService:     svcl,

err := cronEvent.AddSchedule()

What do you think, where should this belong, how would the command invocation would look like?
I thought about sth. like

  • apex cron [functionname] "rate(5 minutes)"
  • apex schedule [functionname] "rate(5 minutes)"
tj commented Jan 27, 2016

niceee! I was thinking just a property in the function.json might be cool, nice to have it in code, I think I'd maybe go with "schedule" as the property, but cron might be more familiar


Oh yes, that's maybe even better!

  "name": "foo",
  "description": "pretty description",
  "runtime": "golang",
  "memory": 128,
  "timeout": 5,
  "role": "<...>",
  "schedule || cron": "rate(5 minutes)"
@tj tj removed the pending AWS support label Jan 27, 2016

IMHO apex/event_sources/cron should be the apex package, because cron is the "tool" that "schedules" and scheduling is an Event Source (AWS terminology):
kind of:

who schedules  what is the schedule
cron rate(5 minutes)

But inside the function.json it is:

"schedule": "rate(5 minutes)"

because it represents the schedule value.
Does this make any sense? :D

tj commented Jan 27, 2016

./sources/cron skips the _ :D

I'd maybe put the bulk of the code in that package, and then call it in a "cron" plugin, similar to these:, using a DeployHook.

That way we keep most of these integrations out of Function methods.

I suppose we should think about config more now too:

  "sources": {
    "schedule": "rate(5 minutes)"

But most will have multiple properties, so maybe we should always make them objects


Ok, so kind of this direction:

Will just have to add

  • function.json parsing
  • propper invocation through the deploy hook
  • prop. refactoring
@tj tj modified the milestone: v0.6.0 Jan 28, 2016
@mthenw mthenw assigned mthenw and unassigned mthenw Jan 29, 2016
@mthenw mthenw added the in progress label Jan 29, 2016
@tj tj removed this from the v0.6.0 milestone Feb 4, 2016
tj commented Feb 4, 2016

closing for now since I'm not sure it's the road we should be going down. In an ideal world we just supported all of AWS without a secondary tool but that's a ton of work and that is basically TF

@tj tj closed this Feb 4, 2016

Sorry to ping a closed issue, but is there anyway this is currently possible or are the TF changes required first? I'm assuming worst case scenario I can modify the function from the Lambda control panel to run on a schedule?

tj commented Feb 23, 2016

@marwanhilmi I think the next release of TF adds it: hashicorp/terraform#4986

@mthenw mthenw removed the in progress label Feb 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment