AWS Cloudwatch event rule: Start and stop time - amazon-web-services

Is it possible to set start and stop time of cloudwatch event rules?
Use Case - I want to create a rule which triggers a lambda, but I want it to run at a specific date (every 2 minutes) and disable it at another date (these date interval can span across months).
As far as I know, when we create a rule (rate (2 minutes)), it starts running immediately. I can use this approach and in the lambda I can check if the current date is same as target date and proceed with lambda execution, and disable the rule when current date is greater than end date. Although, it might work but it does not seem the right approach since lambda would be unnecessarily executing until the target date.
Is there any way I can achieve the same thing without the hack?

Yes, you can set it to specific date only. For instance the following rule 0/2 0 28 9 ? 2020 would execute every 2 minutes on 28 Sep 2020 only:
Update
To span across months, I think you need separate rules. For example you could define two rules to span date range 28 Sep to finish 5 Oct: 0/2 0 28-31 9 ? 2020 and 0/2 0 1-5 10 ? 2020.

Related

django-q multple cron expression for a single job

Is there a way to use multiple cron expression for a single job in Django-Q.
I want a schedule a job for different day of different month.
want to combine this-
At 11:00 on day-of-month 10, 20, and 30 in January and every month from March through December--
0 11 10,20 1,2,4-12 *
At 11:00 on day-of-month 10, 20, and 28 in February.--
0 11 10,20,28 2 *
I don't think we can do that, a better approach will be to keep a single cron that runs on a daily basis and check is there any cron that needs to be run today(we may store the cron info in a database table).

AWS SAM Parameter ScheduleExpression is not valid when adding day of week

I am making a CloudWatch event and I need it to run every Friday at 11pm UTC. I attempted to turn this on by doing cron(0 23 * * FRI *) which according to all documentation I could find, is perfectly correct syntax. However it was failing every time I tried to deploy it.
I found the issue was that if you set a day of the week specifically, then you can not set the third parameter to * it needs to be set to ?. This makes logic sense because the third parameter is Day of Month and so you can't have it run every day of the month AND every Friday. Updating to
cron(0 23 ? * FRI *) solved the problem for me.
An important and I suppose obvious note when setting cron values: Think about how each value affects the other values you've set. Does each one make logical sense in conjunction with the others?

Configure a cron schedule for different intervals (hour and days)

Hello I am configuring jobs in GCP following the google cloud guide: https://cloud.google.com/scheduler/docs/configuring/cron-job-schedules?&_ga=2.226390674.-907001748.1582817924#defining_the_job_schedule
I have to configure a job which will be executed once on weekdays at 6am and once on weekends at 5am. I am not pretty sure if it is possible to configure this for several intervals of time with something like an and statment:
0 5 * * 1-5 # monday to friday 5 am.
0 6 * * 6,0 # saturday and sunday 5 am.
In what way I can combine this intervals, besides that I need to add others ones but I am not pretty sure how can I do this.
Thanks.
You can't combine them in one record. The times do not match on any way. Of course if you have more jobs this eventually can be possible (depend on intervals)

Repeated events in calendar

First of all, please excuse my perfectible English, I am French.
I'm coming to ask for some advice on a database design problem.
I have to design a calendar with events. Briefly, an event includes a start date/time, an end date/time, and a description.
The problem is that I have to consider repetitions; it is possible when creating an event to indicate that it starts next week and repeats itself until a specific date or not.
I see two possibilities of design:
create an events table with id, start_datetime, end_datetime and description fields.
When adding a new event, we generate as many rows as there are repeated events.
Advantages: we can make a SELECT * to retrieve all the events, without particular algorithm. In addition, it is possible to modify the descriptions of each occurrence of an event, insofar as they are considered as all different.
Disadvantage (MAJOR!): If we do not put an end date to have an infinite repetition, we will not memorize an infinity of events...
take inspiration from the method described on this thread, that is to say two tables:
events table
id description
1 Single event on 2018-11-23 08:00-09:30
2 Repeated event :
* every monday from 10:00 to 12:00 from Monday 2018-11-26
* every wednesday from 2018-11-28 from 14:00 to 14:45 until 2019-02-27
event_repetitions table
id event_id start_datetime end_datetime interval end_date
1 1 2018-11-23 08:00:00 2018-11-23 09:30:00 NULL NULL
2 2 2018-11-26 10:00:00 2018-11-26 12:00:00 604800 NULL
3 2 2018-11-28 14:00:00 2018-11-28 14:45:00 604800 2019-02-27
Note: interval is the number of seconds between each occurrence, 604800 = 24 (hours) * 3600 (seconds) * 7 (days).
Advantage: In the case of infinite repetitions (case of the event of id 2), we have very few lines to write and performances are increased.
Disadvantages: if we want to modify the description of the event (or other possible fields) for a specific occurrence and not another, we can not without creating a third table, event_descriptions for example:
id event_id user_id datetime description
1 2 1 2018-11-26 10:00:00 Comment from 2018-11-26
2 2 2 2018-12-03 10:00:00 Comment of the second occurrence, i.e. from 2018-12-03
Note: user_id is the logged-in user who wrote the comment.
Another disadvantage is that to get the list of events for a given day, week, or month, the selection query will be more complex and use joins. The event_descriptions table may, when there are hundreds of thousands of events, be very big.
My question is: what would you recommend as a more effective alternative? Maybe the second solution is good? What do you think?
In terms of technologies used, I intend to go on MySQL, the DBMS I know best. Nevertheless, if you think that using for example MongoDB is better in case of very large numbers of lines, do not hesitate to report it.
For information, my application is an API developed with API Platform, so Symfony 4 with Doctrine ORM.
Thank you in advance for your answers.
I allow myself to do a little up, hoping other answers.

Run Amazon CloudWatch Event every Sunday at 10:00 am UTC

I have already read Amazon CloudWatch Events - Schedule Expressions for Rules.
Now I want to trigger an event every Sunday at 10:00 am and I am confused if this is correct?
Currently I have cron(0 10 * * SUN *) & cron(0 10 ? * SUN *)
I don't know the difference between ? & * in Cronjob. So which one is correct is confusing?
Side Note
What is the difference between rate and schedule because rate is simpler to use so I can do like rate(7 days) but I don't know when it will run?
Will it run every 7 days from the moment of deployment?
That page says:
You can't specify the Day-of-month and Day-of-week fields in the same cron expression. If you specify a value (or a *) in one of the fields, you must use a ? (question mark) in the other.
It also says:
A rate expression starts when you create the scheduled event rule, and then runs on its defined schedule.
To run every Sunday at 10:00 AM UTC,
cron(0 10 ? * SUN *) or cron(0 10 ? * 1 *)
Use ? for Day-of-month part when Day-of-week has a value(here, SUN or 1) because when you want to run only on a specific day of the week, you can't use *, you can't say run everyday. Instead, we should say run one or another day of the month, using ?, which will be every Sunday of the month because we have set Day-of-week.
Refer Schedule Expressions for all details