-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstartJob.py
43 lines (33 loc) · 1 KB
/
startJob.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
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3
import boto3
import json
import time
s3 = boto3.client("s3")
textract_client = boto3.client('textract')
def handler(event, context):
print("event")
print(event)
if event['source'] != 'aws.s3':
raise ValueError("ERROR: Unexpected event type")
bucket_name = event['detail']['bucket']['name']
object_name = event['detail']['object']['key']
print(f"StartJob: s3://{bucket_name}/{object_name}")
job_id = _startJob(bucket_name, object_name)
print(f"JobId: {job_id}")
return {
"bucket_name": bucket_name,
"object_name": object_name,
"job_id": job_id,
"job_start_timestamp": time.time()
}
def _startJob(bucket_name, object_name):
response = textract_client.start_document_analysis(
DocumentLocation={
'S3Object': {
'Bucket': bucket_name,
'Name': object_name,
}
},
FeatureTypes=['TABLES','FORMS'],
)
return response["JobId"]