Last active
October 11, 2018 12:44
-
-
Save rioner/fe5d53efac1c241d4abfcb8dec125ec1 to your computer and use it in GitHub Desktop.
VPC Flow LogsをAthenaで分析できるようにpartitionを区切るやつ
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
import boto3 | |
import datetime | |
def lambda_handler(event, context): | |
# タイムゾーンの生成 | |
JST = timezone(timedelta(hours=+9), 'JST') | |
now = datetime.now(JST) | |
print(now.strftime("%Y/%m/%d")) #2018/10/02 | |
client = boto3.client('athena') | |
response = client.start_query_execution( | |
QueryString="ALTER TABLE ap_northeast_1\nADD PARTITION (dt='" + now.strftime("%Y%m%d") + "')\nlocation 's3://バケット名/AWSLogs/アカウント番号/vpcflowlogs/ap-northeast-1/" + now.strftime("%Y/%m/%d") + "';", | |
QueryExecutionContext={ | |
'Database': 'データベース名' | |
}, | |
ResultConfiguration={ | |
'OutputLocation': 's3://aws-athena-query-results-アカウント番号-ap-northeast-1/' | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment