AWS SAM makes it easy to run a Lambda function on a schedule and pass in a JSON blob as a payload to your function. See the schedule SAM object. But it’s not as clear cut if you are trying to do this same thing with Terraform.

Using Terraform requires two Terraform resources, aws_cloudwatch_event_rule and aws_cloudwatch_event_target.

resource "aws_cloudwatch_event_rule" "scan_schedule" {
  name = "my-daily-event-rule"
  description = "Run my lambda on a daily schedule"

  schedule_expression = "rate(1 day)"
}

resource "aws_cloudwatch_event_target" "lambda" {
  rule      = aws_cloudwatch_event_rule.scan_schedule.name
  arn       = aws_lambda_function.my_func.arn
  input     = file("input.json")
}

The target points a Lambda function definition of yours and pulls in the json payload of a local file.

With this setup you can easily configure a Lambda function to run on a schedule with a specific payload.