Since all of them fail, I decided to specify it in JST and convert it to UTC with CDK.
For the time being, only the definition of CloudWatch Events. Whatever you combine this with Step Functions.
#Define batch schedule in JST (cron expression*The place to do is empty)
props['schedule'] = {
'minute': 40,
'hour': 9,
'week_day': 'MON-FRI'
}
#Convert JST to UTC
if props['schedule'].get('hour') is not None:
props['schedule']['hour'] = props['schedule']['hour'] - 9
if props['schedule']['hour'] < 0:
props['schedule']['hour'] += 24
if props['schedule'].get('day') is not None:
props['schedule']['day'] = props['schedule']['day'] - 1
#JST If it operates by 9 am at the beginning of the month, operate it on a date like the end of the month and judge with Lambda etc.
if props['schedule'].get('day') == 0:
props['schedule']['day'] = '28-31'
# props['schedule']Convert the contents to str
for key in props['schedule'].keys():
props['schedule'][key] = str(props['schedule'][key])
# Cloud Watch Events
Rule = events.Rule(
app, f"Batch-{id}",
schedule=events.Schedule.cron(**props['schedule'])
)
Only whether it is the beginning of the month (1st) of JST is judged and True or False is returned. If you want to incorporate it in StepFunctions, you can judge the return value of this and send it next or finish it, and if it is a simple process, you can continue processing with ʻif result:` in this Lambda.
import datetime
import calendar
def lambda_handler(event, context):
print('===Start Lambda===')
print(event)
dt_now = datetime.datetime.now()
monthrange = calendar.monthrange(dt_now.year, dt_now.month)[1]
result = dt_now.day == monthrange
print(result)
return result
I would be grateful if any wise man who knows something better could point out.