AWS cron expression OK, lambda not triggered

2k views Asked by At

I have set the following cron expression in AWS (CloudWatch trigger).

0 */5 7-12,1pm-11pm ? * MON,TUE,WED,THU,FRI

In expression generator, I get for very similar expresssion (7-23 intead of the hours )

At second :00, every 5 minutes starting at minute :00, every hour between 07am and 23pm, on every Monday, Tuesday, Wednesday, Thursday and Friday, every month as expected.

However, it is not triggered. I don't see anything in the log. The expression is wrong somehow

Why is that? (trigger is enabled of course)

Thanks.

3

There are 3 answers

1
user2679290 On BEST ANSWER

Well, the expression wasn't right.

It considers minutes only and the */5 confused it too maybe. Not sure about the * at the end.

0/5 7-23 ? * MON-FRI * - this works

To debug triggers, there is "Rules" section in the log service, where you can see the next executions.

0
Debu Shinobi On

Since the CRON expression is in UTC time format. Could you please check if there is any time difference b/w your standard time and UTC time?

And change the expression accordingly.

5
Binh Nguyen On

When you create CloudWatch Event Rule, or EventBridge Event Rule (is what AWS calls these days) and select Lambda function as target, there are 2 main points that you need to consider:

  1. CRON SCHEDULE

You need to specify the cron schedule and this schedule timezone is UTC+0.

I assume that you are in different timezone and observe there is not any triggers since the next trigger time has not been reached yet.

  1. RESOUCE-BASED POLICY

There is another chance that you need to check is about permissions, you need to concern is Lambda function's Resource Based Policy.

Go to AWS Console, you can check your Lambda's permission tab and review your permissions which is required to allow your Event Rule triggers.

{
  "Version": "2012-10-17",
  "Id": "default",
  "Statement": [
    {
      "Sid": "AWSEvents",
      "Effect": "Allow",
      "Principal": {
        "Service": "events.amazonaws.com"
      },
      "Action": "lambda:InvokeFunction",
      "Resource": "arn:aws:lambda:<REGION>:<ACCOUNT_ID>:function:<FUNCTION_NAME>",
      "Condition": {
        "ArnLike": {
          "AWS:SourceArn": "arn:aws:events:<REGION>:<ACCOUNT_ID>:rule/<RULE_NAME>"
        }
      }
    }
  ]
}