From 7a5fae6dec2aabe6709727f4fabe92c18f1e8ab7 Mon Sep 17 00:00:00 2001 From: Kuba Date: Sun, 5 Feb 2023 19:26:53 +0100 Subject: [PATCH] serverless & client --- .gitignore | 1 + README.md | 7 +- invoice/index.html | 193 +++++---------------------------------------- invoice/lambda.py | 11 ++- 4 files changed, 38 insertions(+), 174 deletions(-) diff --git a/.gitignore b/.gitignore index 0deeb9e..3b2916a 100644 --- a/.gitignore +++ b/.gitignore @@ -153,3 +153,4 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ +*.pdf \ No newline at end of file diff --git a/README.md b/README.md index 97c1ef8..dcc5b5f 100644 --- a/README.md +++ b/README.md @@ -5,4 +5,9 @@ - clone lambda.py code into your lambda trigger - Add S3 bucket to your Lambda Trigger - Add invoice to your bucket - - Enjoy! \ No newline at end of file + - Enjoy! + + + ## Application based on double requests: + - PUT https://9kpwan8769.execute-api.us-east-1.amazonaws.com/textract/{bucket-name}/{file-name} to send file to S3 and trigger serverless Textract + - GET https://gp1q182wu2.execute-api.us-east-1.amazonaws.com/read to read textract result from database \ No newline at end of file diff --git a/invoice/index.html b/invoice/index.html index e8739c3..d4a5a86 100644 --- a/invoice/index.html +++ b/invoice/index.html @@ -1,176 +1,25 @@ - - - - Upload file to S3 - - - - -
-

S3 Uploader Test

- -
-

Select an image

- -
-
- - - -
-

Success! Image uploaded to bucket.

-
+ + + - + resp = await fetch('https://9kpwan8769.execute-api.us-east-1.amazonaws.com/textract/bucket-textract-s478874/prod.pdf', {method: "PUT", body: data}) + document.getElementById("result").innerHTML = "Info" + data = await resp.json() - - - + + Chmura + + + +

+ \ No newline at end of file diff --git a/invoice/lambda.py b/invoice/lambda.py index ae9b80e..df64ad2 100644 --- a/invoice/lambda.py +++ b/invoice/lambda.py @@ -2,6 +2,7 @@ import boto3 from collections import defaultdict from urllib.parse import unquote_plus import json +import base64 def print_labels_and_values(field, keys): if "LabelDetection" in field and "ValueDetection" in field: @@ -42,4 +43,12 @@ def lambda_handler(event, context): table = dynamodb.Table('texttract-s478874') - table.put_item(Item=invoice_data) \ No newline at end of file + table.put_item(Item=invoice_data) + + + responseObj = {} + responseObj['statusCode'] = 200 + responseObj['headers'] = {} + responseObj['body'] = json.dumps(invoice_data) + + return responseObj \ No newline at end of file