0
votes

I am facing issues with passing cron expression as parameter to stack. Seems parameter is getting evaluated to differently than expected. Below are details:

  1. Reading cron expression from json file.

    { "CronSchedule":""cron(0 19 * * * *)"" }

  2. Code snippet of my cloudformation stack.

      ScheduledRule: 
        Type: AWS::Events::Rule 
          Properties: 
          Description: ScheduledRule 
          Name: !Sub '${Environment}-${Platform}-${AppName}-${Prefix}-SCHEDULE-CAPTURE' 
          ScheduleExpression: !Sub ${CronSchedule} 
          State: "ENABLED"
    
  3. AWS command executing:

    aws --region us-east-1 cloudformation deploy --template-file ./deployment/aws/cfn/cloudwatch-resources.yml --stack-name QA-DUMMYAPP-CLOUD-WATCH --parameter-overrides Owner=DUMMYAPP AppID=C4E7876D-1BF6-0090-868C-A8E82D4BCBCD BU=DJI AppName=DUMMYAPP Platform=T3 LambdaStackName=QA-DUMMYAPP-LAMBDA ApiGwResourcesStackName=QA-DUMMYAPP-API-GW-RESOURCES CloudWatchStackName=QA-DUMMYAPP-CLOUD-WATCH FeedStateMachineStackName=STACK_NAME Environment=QA CronSchedule="cron(0 19 * * * *)" --no-fail-on-empty-changeset

  4. On AWS Console, cronShedule is displayed as below on the parameter tab.

    CronSchedule = *cron(0 19 config deployment pom.xml README.md scripts src config deployment pom.xml README.md scripts src config deployment pom.xml README.md scripts src )

The issue seems to be * is replaced with directory/file names under the directory where cloudformation command is executed.

Any help would be appreciated.

2
Have you tried with single quotes? CronSchedule='cron(0 19 * * * *)'? - Marcin
Yes, I tried both single quote and double quotes - Venkata Neralla
I tried to replicate the issue, but it works fine in my tests. Do you execute it on linux and bash? - Marcin
Yes. Now I noticed another behavior. Irrespective of value passed as parameter it is resolving to "cron(0 19 config deployment pom.xml README.md scripts src config deployment pom.xml README.md scripts src config deployment pom.xml README.md scripts src *)". Example: Passed CronSchedule='cron(0 19 6 7 6L 2002-2005)' as parameter to cloudformation stack and when stack started execution in parameter tab it shows correct value, but after wards it gets changed to whatever I mentioned above - Venkata Neralla
Must be something else happening. May check in other terminal, or some simplified version of your deploy command. - Marcin

2 Answers

1
votes

It works for me passing the variable like this:

CronSchedule="'cron(0 19 * * * *)'"

0
votes

You should use the wildcard in the expression. Check the following link Schedule Expressions for Rules