Skip to content

Commit e01636d

Browse files
added Lambda Handler code
1 parent 68031f2 commit e01636d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Lambda_Code/ExtractDocumentText.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import json
2+
import boto3
3+
4+
def lambda_handler(event, context):
5+
print(event)
6+
object_key = event.get('file_name', None)
7+
8+
textract_client = boto3.client('textract')
9+
10+
# Call the analyze_document API
11+
response = textract_client.analyze_id(
12+
DocumentPages=[{'S3Object': {'Bucket': 'one-id-resource', 'Name': object_key}}]
13+
)
14+
dic = {}
15+
16+
# Extract the text from the response
17+
extracted_text = ''
18+
for doc_fields in response['IdentityDocuments']:
19+
for id_field in doc_fields['IdentityDocumentFields']:
20+
for key, val in id_field.items():
21+
if "Type" in str(key):
22+
x = val['Text']
23+
for key, val in id_field.items():
24+
if "ValueDetection" in str(key):
25+
dic[x] = val['Text']
26+
27+
# Convert data to JSON string
28+
json_data = json.dumps(dic)
29+
30+
return json_data

0 commit comments

Comments
 (0)