skip to Main Content

Have defined an EventBridge rule, which is disabled by default.

    new Rule(this, 'EmailRule', {
      ruleName: 'email-event-rule',
      description: 'trigger email handler',
      enabled: false,
      eventPattern: {
        detailType: ['email-event-rule-event']
      },
      targets: [new LambdaFunction(emailHandlerConstruct.getLambda())],
      schedule: Schedule.rate(Duration.hours(1))
    });

In a certain scenario it is enabled. But I assumed it would run after an hour of being enabled. But it triggers the lambda every time its enabled right away.

Is that how its designed or am I missing something? I did not see anywhere in the doc regarding the schedule of an event bridge rule when it is enabled.

2

Answers


  1. Good question. The doc only mentions that it fires right away on the rule creation. Therefore, this behaviour is undocumented and you are not missing anything.

    Login or Signup to reply.
  2. That is indeed how it is designed. When you create an Eventbridge rule that uses a rate expression instead of a schedule (such as your example), it will run the moment it is created and then run again after whatever period of time you specified has passed. In your example it seems like you want the rule to trigger the lambda every hour. When the rule gets created it then triggers the lambda right away, and then will do it again every hour after that. This means that if you deployed the rule at 1:30pm then it would repeat at 2:30pm, 3:30pm etc. etc.

    Link to AWS documentation about rate expression Eventbridge rules: https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-create-rule-schedule.html

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search