Search code examples
javaamazon-web-servicescronamazon-cloudwatch

AWS cron expression to run a job every 2 days once


I have a requirement to schedule a job in AWS CloudWatch events to be run once in every two days. I am using the below expression but getting a error Parameter ScheduleExpression is not valid

cron(0 0 */2 * ? *)

The below is the java code,

String cronExpression = "cron(0 0 */2 * ? *)"
    PutRuleRequest request = new PutRuleRequest();
        request
            .withName(eventName)
            .withRoleArn("arn:aws:iam::****")
            .withScheduleExpression(cronExpression)
            .withState(RuleState.ENABLED);
        PutRuleResult result = cloudwatchConfig.cloudwatch().putRule(request);

Solution

  • cron(0 0 1/2 * ? *)
    

    You can verify here.