gpt4 book ai didi

python - Boto3 定时任务 : Parameter ScheduleExpression is not valid

转载 作者:太空宇宙 更新时间:2023-11-04 02:57:26 26 4
gpt4 key购买 nike

我正在尝试在执行 15 分钟后安排事件:

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")

这给我的错误是

Parameter ScheduleExpression is not valid.

知道为什么吗?

最佳答案

http://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html#CronExpressions

第一个值应该是分钟,第二个值应该是小时。

所以你的代码应该是:

cronJob = "cron(" + str(d.minute) + " " + str(d.hour) + " * * ? *)"

而不是 “cron(” + str(d.hour) + “” + str(d.minute) + “* * ? *)”

关于python - Boto3 定时任务 : Parameter ScheduleExpression is not valid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41955063/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com