Last active
October 31, 2019 09:11
-
-
Save broccoli1002/026828c7b7fa95c52b86e42f943b60f5 to your computer and use it in GitHub Desktop.
lambda自動実行
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# usage: python3 hoge.py us-east-1 20190926 | |
import boto3 | |
import datetime | |
import json | |
import sys | |
REGION = sys.argv[1] | |
YYYYMMDD_UTC = datetime.datetime.strptime(sys.argv[2], '%Y%m%d') | |
DRY_RUN = False | |
DAILY_LAMBDA_FUNC_NAME = "XXXXX" | |
HOURLY_LAMBDA_FUNC_NAME = "XXXXX" | |
client = boto3.client('lambda', region_name=REGION) | |
for hours in range(1, 25): | |
payload= { | |
"time": datetime.datetime.isoformat(YYYYMMDD_UTC + datetime.timedelta(hours=hours)) + 'Z' | |
} | |
print(f'> LAMBDA: {HOURLY_LAMBDA_FUNC_NAME}, PAYLAOD: {payload}') | |
if not DRY_RUN: | |
res = client.invoke( | |
FunctionName=HOURLY_LAMBDA_FUNC_NAME, | |
Payload=json.dumps(payload) | |
) | |
print(res) | |
payload= { | |
"time": datetime.datetime.isoformat(YYYYMMDD_UTC) + 'Z' | |
} | |
print(f'> LAMBDA: {DAILY_LAMBDA_FUNC_NAME}, PAYLAOD: {payload}') | |
if not DRY_RUN: | |
res = client.invoke( | |
FunctionName=DAILY_LAMBDA_FUNC_NAME, | |
Payload=json.dumps(payload) | |
) | |
print(res) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment