0

Can we edit the AWS event scheduler rule to change the duration via program, script or lambda?

enter image description here

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
ANK
  • 537
  • 7
  • 12

1 Answers1

7

The event schedule is defined within AWS EventBridge. This service makes sure to trigger whatever service you need and configure in your rule, e.g. a Lambda function, an SNS topic, etc.

Yes, you can change the event schedule. If you're using the AWS CLI, you can use the put-rule command which creates or updates an event rule:

aws events put-rule --name <rule-name> --schedule-expression "rate(1 day)"

Take care of the following note in the command description:

If you are updating an existing rule, the rule is replaced with what you specify in this PutRule command. If you omit arguments in PutRule , the old values for those arguments are not kept. Instead, they are replaced with null values.

If you want to update the rule from a Lambda function, you can use the AWS SDK to accomplish this. For example, if you're using the Node.js SDK, then the putRule documentation should help you. It's similar to the CLI command above:

var eventbridge = new AWS.EventBridge();
eventbridge.putRule({
  name: '<name>',
  scheduleExpression: 'rate(1 day)'
}, function (err, data) {
  // Your callback code
});
s.hesse
  • 1,900
  • 10
  • 13
  • Thanks for the above answer. Can we format the scheduleExpression? something like duration = "rate("+value+" minute)" scheduleExpression = duration – ANK Jan 16 '21 at 14:06
  • 1
    Do you mean if you can use `value` as a variable based on some input and then set the schedule expression using this dynamic value? Sure, this should be possible. It just depends on the syntax of the programming language you're using. (If you meant something else, then please make your question a bit more clear :) ) – s.hesse Jan 17 '21 at 12:20
  • You're welcome! Feel free to accept my answer if it solved your question :) – s.hesse Jan 17 '21 at 14:48