TABLE) from datetime import datetime import boto3 import os def lambda_handler(event, context): dt = datetime.now().strftime("%Y-%m-%d") hour = datetime.now().strftime("%H") s3bucket = os.environ['s3bucket'] s3key = os.environ['s3key'] gluedb = os.environ['gluedb'] gluetable = os.environ['gluetable'] athena = boto3.client('athena') sql = "ALTER TABLE " + gluetable + " ADD IF NOT EXISTS PARTITION (dt='" + dt + "',hour='" + hour + "') location 's3://xxxxxx/firehose/IIS_logs_2/dt=" + dt + "/hour=" + hour + "'" print('sql:' + sql) athena.start_query_execution( QueryString= sql , QueryExecutionContext={ 'Database': gluedb }, ResultConfiguration={ 'OutputLocation': 's3://' + s3bucket + '/athena-output' } )