copilot-cli
copilot-cli copied to clipboard
The use can specify the timezone of the schedule expression in Scheduled Job
In my workload manifest.yml
I have the following cron schedule:
name: morning-report
type: Scheduled Job
on:
schedule: "cron(0 9 ? * MON-FRI *)"
But the time is assumed in UTC and the timezone can't be changed. It would be nice if the manifest could map the EventBridge scheduler option:
aws scheduler create-schedule \
--schedule-expression "at(2022-11-20T13:00:00)" \
--name schedule-name \
--schedule-expression-timezone "America/Los_Angeles"
Hi @RaffaeleSgarro !
Your feature request makes sense to me, if anything Copilot could translate the schedule expression from one timezone to another.
The manifest could be something like:
on:
schedule: "cron(0 9 ? * MON-FRI *)"
schedule_timezone: "America/Los_Angeles"
Great! How does it work now? Do you point me to some documentation to implement it myself and send a pull request, or is it so trivial that you prefer to fix it yourself?
How does it work now? Do you point me to some documentation to implement it myself and send a pull request, or is it so trivial that you prefer to fix it yourself?
Typically, if it's going to be implemented by the AWS Copilot team we'll need to prioritize the feature request first. We update the GitHub issues saying that the team is now picking up the feature request so that users are aware of the progress.
Unfortunately, I can't make a commitment today for a timeline for the feature. However, if you'd like to send a pull-request we'd be happy to review it!
If you'd like to contribute the feature, I believe the following changes need to happen:
-
Adding the
timezone
field to the manifest file: https://github.com/aws/copilot-cli/blob/499bb1ca37b11a9955377594ac8c8826bb7d7ce8/internal/pkg/manifest/job.go#L45-L47 -
Adding validation for the new field to ensure that the string entered is a valid timezone: https://github.com/aws/copilot-cli/blob/499bb1ca37b11a9955377594ac8c8826bb7d7ce8/internal/pkg/manifest/validate.go#L1550-L1557
-
Convert the cron job expression from one timezone to the next here: https://github.com/aws/copilot-cli/blob/499bb1ca37b11a9955377594ac8c8826bb7d7ce8/internal/pkg/deploy/cloudformation/stack/scheduled_job.go#L245 (although I think the last step isn't trivial)
I'd also like to see this implemented. However, just translating the expressions, before passing it to the template engine is insufficient for reoccurring jobs. The advantage of being able to select timezone is daylight savings handling.
If someone were able to rewrite the template to use AWS::Scheduler::Schedule, instead of the, currently used, AWS::Events::Rule, we'd be able to have native timezone support.
The existing template is here: https://github.com/aws/copilot-cli/blob/4b8eccbe24a9e03ff1b35ae17163a287aa3062db/internal/pkg/template/templates/workloads/partials/cf/eventrule.yml#L1-L37
I ended up using the following YAML patch overrides to support my use case. May follow up with a PR to do the work described in my comment above, if there is interest. If anyone knows, if there is a way to add support for grabbing the time zone value from the manifest yaml, please let me know.
################################################################################################################
######################################### Time zone Support #########################################
################################################################################################################
## Replaces AWS::Events::Rule with AWS::Scheduler::Schedule to take advtange of EventBridge Scheduler's ##
## time zone support. See TR-209 ##
################################################################################################################
# Update RuleRole to allow Scheduler
- op: replace
path: /Resources/RuleRole/Properties/AssumeRolePolicyDocument/Statement/0/Principal/Service
value: scheduler.amazonaws.com
# Use EventBridge Scheduler instead of CloudWatch Events
- op: replace
path: /Resources/Rule/Type
value: 'AWS::Scheduler::Schedule'
- op: add
path: /Resources/Rule/Properties/FlexibleTimeWindow
value:
# Must have quotes
Mode: "OFF"
- op: add
path: /Resources/Rule/Properties/ScheduleExpressionTimezone
# Set your timezone here as an IANA time zone
value: "America/Chicago"
- op: remove
path: /Resources/Rule/Properties/Targets
- op: add
path: /Resources/Rule/Properties/Target
value:
Arn: !Ref StateMachine
RoleArn: !GetAtt RuleRole.Arn
################################################################################################################
######################################### End time zone Support #########################################
################################################################################################################
Hello!!! I am interested in this, I am trying to see if I can solve this by employing EventBridge Scheduler.