首页 > 解决方案 > 如何为每个季度添加 CloudWatch 计划事件规则?

问题描述

我正在尝试设置将在每年每个季度运行的 CloudWatch 计划事件规则。但我收到了这个错误

"Parameter ScheduleExpression is not valid".

我尝试遵循 Cron 表达式

cron(0 0 1 */3 * ?) 
cron(0 0 1 */3 ? *) 

但不工作。有人可以帮忙吗?

标签: cronscheduled-tasksamazon-cloudwatch

解决方案


根据AWS 文档

您不能在 Day-of-month 和 Day-of-week 字段中都使用 *。如果你在一个中使用它,你必须使用 ? 在另一个。

此外,年份字段不支持?通配符,因此您的第一个表达式无效。

第二个有效:

aws events put-rule --schedule-expression "cron(0 0 1 */3 ? *)" --name so-test1
{
    "RuleArn": "arn:aws:events:eu-west-1:3333:rule/so-test1"
}

右括号后有空格吗?那个标记为对我无效

aws events put-rule --schedule-expression "cron(0 0 1 */3 ? *) " --name so-test1

An error occurred (ValidationException) when calling the PutRule operation: Parameter ScheduleExpression is not valid.

推荐阅读