Issue
I am trying to schedule event just after 15 minute of execution as:
client = boto3.client('events')
d = datetime.now() + timedelta(minutes=40)
cronJob = "cron(" + str(d.hour) + " " + str(d.minute) + " * * ? *)"
client.put_rule(Name='extractData', ScheduleExpression=cronJob, State='ENABLED', Description='This is rule extracting flurry data')
try:
client.put_targets( Rule='extractData', Targets=[ { 'Id': '1', 'Arn': 'arn:aws:lambda:ap-southeast-1:381409677897:function:flurry_extractReportOnDemand' }])
except:
print("\n###################\n")
print ("Could not schedule")
print("\n###################\n")
This is giving me error as
Parameter ScheduleExpression is not valid.
Any idea why ?
Solution
http://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html#CronExpressions
The first value should be minutes and second value should be hours.
So your code should be:
cronJob = "cron(" + str(d.minute) + " " + str(d.hour) + " * * ? *)"
instead of "cron(" + str(d.hour) + " " + str(d.minute) + " * * ? *)"
Answered By - anupsabraham Answer Checked By - Gilberto Lyons (WPSolving Admin)