4

I'd like to run a Lambda task on a fixed schedule, with some configuration passed into it by the CloudWatch Scheduled Event that triggers the task. Looking at the documentation here, I can see that Cloudwatch Scheduled Events look like this:

{
  "id": "53dc4d37-cffa-4f76-80c9-8b7d4a4d2eaa",
  "detail-type": "Scheduled Event",
  "source": "aws.events",
  "account": "123456789012",
  "time": "2015-10-08T16:53:06Z",
  "region": "us-east-1",
  "resources": [ "arn:aws:events:us-east-1:123456789012:rule/MyScheduledRule" ],
  "detail": {}
}

My Lambda task is written in Go, and I can see that event.CloudWatchEvent lets me access the JSON in the event's detail field, but I can't figure out how to create a Cloudwatch Scheduled Event rule with some custom detail. Any thoughts?

Chris
  • 347
  • 3
  • 6
  • 13
  • you may want to move this questions to just `stackoverflow` from `serverfault` for good visibility by AWS team – Pradeep May 23 '19 at 17:09

2 Answers2

3
# This is for AWS Sam CF
MyScheduledRule:
    Type: "AWS::Events::Rule"
    Properties:
      Description: "ScheduledRule"
      ScheduleExpression: "rate(6 minutes)"
      State: "ENABLED"
      Targets:
        - Arn:
            !GetAtt MyLambdaFunction.Arn
          Id: "IdForAlert" 
          Input: "{\"name\": \"value\"}"
0

It's not a perfect answer, but I wound up communicating to the Lambda task using env vars.

https://docs.aws.amazon.com/lambda/latest/dg/env_variables.html

Chris
  • 347
  • 3
  • 6
  • 13