-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathunzip.py
30 lines (25 loc) · 952 Bytes
/
unzip.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
import boto3
def handler(event, context):
"""
trigger a glue job that will unzip zip files stored on s3.
"""
# get the source key and bucket from
# the event that triggered this lambda_function function.
source_key = event['Records'][0]['s3']['object']['key']
source_bucket = event['Records'][0]['s3']['bucket']['name']
# get the destination key and bucket from
# the environment variables
glue_job = os.getenv('GLUE_JOB')
destination_bucket = os.getenv('DEST_BUCKET')
destination_key = os.getenv('DEST_KEY')
# build args object and start the glue job
args = {
'--source_bucket': source_bucket,
'--source_key': source_key,
'--destination_bucket': destination_bucket,
'--destination_key': destination_key,
}
print('args for glue job: {}'.format(args))
return boto3.client('glue')\
.start_job_run(JobName=glue_job, Arguments=args)