I have to setup "AWS::Events::Rule" in cloudwatch with ScheduleExpression(10 days), and write some code to test it, but I can not change the "10 days" to 1 minute or call the lambda function directly. I know that we can call put event for calling a rule with EventPattern. But not know how to do that for ScheduleExpression. Any comment is welcome, Thanks.
3 Answers
0
votes
0
votes
I also met this problem. I checked AWS document and it says that a rule can only contain either EventPattern or ScheduleExpression. But in order to call aws events put-events
we must provide a Source for EventPattern match. So I think we cannot manually trigger a scheduled event.
Not sure what's your use case, but I have decided to move to use Invoke API of AWSLambda client.
0
votes
SDK Approach: Yes, you can use the putRule SDK function to update the ScheduleExpression of the CloudWatch Rule. As I mentioned in the below snippet
let params =
{
Name: timezoneCronName, /* required */
ScheduleExpression: cronExpression
}
return CloudWatchEvents.putRule(cloudWatchEventsParams).promise().then((response) => {
console.debug(`CloudWatch Events response`, response);
return response;
}).catch((error) => {
console.error(`Error occurred while updating Cloud Watch Event:${error.message}`);
throw error;
});
See this Official AWS SDK DOC.
CLI Approach:
Run the following command though CLI
aws events put-rule --name "You Rule ARN" --schedule-expression "cron(0/1 * * * ? *)"