Skip to content

Commit 179d8b0

Browse files
authored
Add files via upload
1 parent ef1aba0 commit 179d8b0

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

lambda_function.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import boto3
2+
import json
3+
4+
def lambda_handler(event, context):
5+
glue_client = boto3.client('glue')
6+
7+
# Extract file key from the S3 event
8+
key = event['Records'][0]['s3']['object']['key']
9+
10+
# We know our target path is 'raw/inventory/'
11+
if key.startswith('raw/inventory/'):
12+
try:
13+
# Prepare Glue job arguments
14+
arguments = {
15+
'--file_name': key.split('/')[-1],
16+
'--enable-continuous-cloudwatch-log': 'true'
17+
}
18+
19+
response = glue_client.start_job_run(
20+
JobName='job',
21+
Arguments=arguments,
22+
Timeout=300
23+
)
24+
25+
print(f"Glue job triggered successfully. JobRunId: {response['JobRunId']}")
26+
except Exception as e:
27+
print(f"Error triggering Glue job: {str(e)}")
28+
raise e
29+
else:
30+
print(f"File {key} is not in the inventory folder. Ignoring the event.")
31+
32+
return {
33+
'statusCode': 200,
34+
'body': json.dumps('Lambda function executed successfully.')
35+
}

0 commit comments

Comments
 (0)