From 459e67bffdc114e91ba75eaef480087b1e7b03dd Mon Sep 17 00:00:00 2001 From: pljhll Date: Sun, 24 May 2020 18:34:42 +0000 Subject: [PATCH 1/4] Removing InvokeTextract lambda --- InvokeTextract/SampleEvent.json | 38 --------------------------------- InvokeTextract/src/app.py | 21 ------------------ 2 files changed, 59 deletions(-) delete mode 100644 InvokeTextract/SampleEvent.json delete mode 100644 InvokeTextract/src/app.py diff --git a/InvokeTextract/SampleEvent.json b/InvokeTextract/SampleEvent.json deleted file mode 100644 index 96d7613..0000000 --- a/InvokeTextract/SampleEvent.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "Records": [ - { - "eventVersion": "2.0", - "eventName": "ObjectCreated:Put", - "eventTime": "1970-01-01T00:00:00.000Z", - "userIdentity": { - "principalId": "EXAMPLE" - }, - "eventSource": "aws:s3", - "requestParameters": { - "sourceIPAddress": "127.0.0.1" - }, - "s3": { - "configurationId": "testConfigRule", - "object": { - "eTag": "1c43a0c9dcc31572b5e49c0b42f8b17f", - "key": "INSERT FILENAME HERE (e.g. receipt.png)", - "sequencer": "0A1B2C3D4E5F678901", - "size": 1024 - }, - "bucket": { - "ownerIdentity": { - "principalId": "EXAMPLE" - }, - "name": "INSERT BUCKET NAME HERE (e.g. aws-sam-ocr-sourceimagebucket-123122312)", - "arn": "arn:aws:s3:::INSERT BUCKET NAME HERE (e.g. aws-sam-ocr-sourceimagebucket-123122312)" - }, - "s3SchemaVersion": "1.0" - }, - "responseElements": { - "x-amz-id-2": "EXAMPLE123/5678abcdefghijklambdaisawesome/mnopqrstuvwxyzABCDEFGH", - "x-amz-request-id": "EXAMPLE123456789" - }, - "awsRegion": "us-east-1" - } - ] -} \ No newline at end of file diff --git a/InvokeTextract/src/app.py b/InvokeTextract/src/app.py deleted file mode 100644 index fd07475..0000000 --- a/InvokeTextract/src/app.py +++ /dev/null @@ -1,21 +0,0 @@ -from urllib.parse import unquote_plus - -import boto3 - -s3_client = boto3.client('s3') -textract_client = boto3.client('textract') - -# SNS_TOPIC_ARN = 'arn:aws:sns:eu-west-1:832044451952:AmazonTextract-TarkovTopic' # We need to create this -# ROLE_ARN = 'arn:aws:iam::832044451952:role/TextractServiceRole' # This role is managed by AWS - -def lambda_handler(event, _): - print(f'Event: {event}') - # for record in event['Records']: - # bucket = record['s3']['bucket']['name'] - # key = unquote_plus(record['s3']['object']['key']) - - # print(f'Document detection for {bucket}/{key}') - - # textract_client.start_document_text_detection( - # DocumentLocation={'S3Object': {'Bucket': bucket, 'Name': key}}, - # NotificationChannel={'RoleArn': ROLE_ARN, 'SNSTopicArn': SNS_TOPIC_ARN}) \ No newline at end of file From b5f2c07b8476c7dd5099b2c9facdb664c0b71639 Mon Sep 17 00:00:00 2001 From: pljhll Date: Sun, 24 May 2020 18:35:10 +0000 Subject: [PATCH 2/4] Importing invokeTarkovTextract lambda --- invokeTarkovTextract/.gitignore | 1 + invokeTarkovTextract/SampleEvent.json | 38 +++++++++++++++++++++++++ invokeTarkovTextract/lambda_function.py | 21 ++++++++++++++ invokeTarkovTextract/template.yaml | 14 +++++++++ 4 files changed, 74 insertions(+) create mode 100644 invokeTarkovTextract/.gitignore create mode 100644 invokeTarkovTextract/SampleEvent.json create mode 100644 invokeTarkovTextract/lambda_function.py create mode 100644 invokeTarkovTextract/template.yaml diff --git a/invokeTarkovTextract/.gitignore b/invokeTarkovTextract/.gitignore new file mode 100644 index 0000000..cd9c024 --- /dev/null +++ b/invokeTarkovTextract/.gitignore @@ -0,0 +1 @@ +.application.json diff --git a/invokeTarkovTextract/SampleEvent.json b/invokeTarkovTextract/SampleEvent.json new file mode 100644 index 0000000..96d7613 --- /dev/null +++ b/invokeTarkovTextract/SampleEvent.json @@ -0,0 +1,38 @@ +{ + "Records": [ + { + "eventVersion": "2.0", + "eventName": "ObjectCreated:Put", + "eventTime": "1970-01-01T00:00:00.000Z", + "userIdentity": { + "principalId": "EXAMPLE" + }, + "eventSource": "aws:s3", + "requestParameters": { + "sourceIPAddress": "127.0.0.1" + }, + "s3": { + "configurationId": "testConfigRule", + "object": { + "eTag": "1c43a0c9dcc31572b5e49c0b42f8b17f", + "key": "INSERT FILENAME HERE (e.g. receipt.png)", + "sequencer": "0A1B2C3D4E5F678901", + "size": 1024 + }, + "bucket": { + "ownerIdentity": { + "principalId": "EXAMPLE" + }, + "name": "INSERT BUCKET NAME HERE (e.g. aws-sam-ocr-sourceimagebucket-123122312)", + "arn": "arn:aws:s3:::INSERT BUCKET NAME HERE (e.g. aws-sam-ocr-sourceimagebucket-123122312)" + }, + "s3SchemaVersion": "1.0" + }, + "responseElements": { + "x-amz-id-2": "EXAMPLE123/5678abcdefghijklambdaisawesome/mnopqrstuvwxyzABCDEFGH", + "x-amz-request-id": "EXAMPLE123456789" + }, + "awsRegion": "us-east-1" + } + ] +} \ No newline at end of file diff --git a/invokeTarkovTextract/lambda_function.py b/invokeTarkovTextract/lambda_function.py new file mode 100644 index 0000000..9902ef9 --- /dev/null +++ b/invokeTarkovTextract/lambda_function.py @@ -0,0 +1,21 @@ +from urllib.parse import unquote_plus + +import boto3 + +s3_client = boto3.client('s3') +textract_client = boto3.client('textract') + +SNS_TOPIC_ARN = 'arn:aws:sns:eu-west-1:832044451952:AmazonTextract-TarkovTopic' # We need to create this +ROLE_ARN = 'arn:aws:iam::832044451952:role/TextractServiceRole' # This role is managed by AWS + +def lambda_handler(event, _): + print(f'Event: {event}') + for record in event['Records']: + bucket = record['s3']['bucket']['name'] + key = unquote_plus(record['s3']['object']['key']) + + print(f'Document detection for {bucket}/{key}') + + textract_client.start_document_text_detection( + DocumentLocation={'S3Object': {'Bucket': bucket, 'Name': key}}, + NotificationChannel={'RoleArn': ROLE_ARN, 'SNSTopicArn': SNS_TOPIC_ARN}) \ No newline at end of file diff --git a/invokeTarkovTextract/template.yaml b/invokeTarkovTextract/template.yaml new file mode 100644 index 0000000..be39fa5 --- /dev/null +++ b/invokeTarkovTextract/template.yaml @@ -0,0 +1,14 @@ +AWSTemplateFormatVersion: '2010-09-09' +Transform: 'AWS::Serverless-2016-10-31' +Description: An AWS Serverless Specification template describing your function. +Resources: + invokeTarkovTextract: + Type: 'AWS::Serverless::Function' + Properties: + FunctionName: invokeTarkovTextract + Description: '' + Handler: lambda_function.lambda_handler + MemorySize: 128 + Role: 'arn:aws:iam::832044451952:role/TarkovLambdaRole' + Runtime: python3.8 + Timeout: 3 From 306664e1ae905baee90bcb5e5767b6bf3ffd0115 Mon Sep 17 00:00:00 2001 From: pljhll Date: Sun, 24 May 2020 19:19:14 +0000 Subject: [PATCH 3/4] Adding .application.json to .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b57c74c..f0fc801 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.aws-sam/ \ No newline at end of file +.aws-sam/ +.application.json From 60445bcc8f3f0a73009e020e76fdea6423190a32 Mon Sep 17 00:00:00 2001 From: pljhll Date: Sun, 24 May 2020 19:19:56 +0000 Subject: [PATCH 4/4] Removing old requirements.txt file from InvokeTextract. --- requirements.txt | 77 ------------------------------------------------ 1 file changed, 77 deletions(-) delete mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 59b8cb6..0000000 --- a/requirements.txt +++ /dev/null @@ -1,77 +0,0 @@ -arrow==0.15.5 -astroid==1.6.6 -attrs==19.3.0 -aws-lambda-builders==0.6.0 -aws-sam-cli==0.38.0 -aws-sam-translator==1.19.0 -awscli==1.18.57 -backcall==0.1.0 -binaryornot==0.4.4 -boto3==1.12.14 -botocore==1.16.7 -certifi==2019.11.28 -chardet==3.0.4 -chevron==0.13.1 -Click==7.0 -colorama==0.4.3 -cookiecutter==1.6.0 -dateparser==0.7.2 -decorator==4.4.2 -Django==2.0.2 -docker==4.2.0 -docutils==0.15.2 -Flask==1.0.4 -future==0.18.2 -git-remote-codecommit==1.13 -idna==2.8 -ikp3db==1.4.1 -importlib-metadata==1.5.0 -ipython==7.14.0 -ipython-genutils==0.2.0 -isort==4.3.21 -itsdangerous==1.1.0 -jedi==0.11.1 -Jinja2==2.11.1 -jinja2-time==0.2.0 -jmespath==0.9.5 -jsonschema==3.2.0 -lazy-object-proxy==1.4.3 -MarkupSafe==1.1.1 -mccabe==0.6.1 -parso==0.1.1 -pbr==5.4.5 -pexpect==4.8.0 -pickleshare==0.7.5 -poyo==0.5.0 -prompt-toolkit==3.0.5 -ptyprocess==0.6.0 -pyasn1==0.4.8 -Pygments==2.6.1 -pylint==1.8.1 -pylint-django==0.8.0 -pylint-flask==0.5 -pylint-plugin-utils==0.6 -pyrsistent==0.15.7 -python-dateutil==2.8.1 -pytz==2020.1 -PyYAML==5.3.1 -regex==2020.2.20 -requests==2.22.0 -rsa==3.4.2 -s3transfer==0.3.3 -serverlessrepo==0.1.9 -six==1.14.0 -stevedore==1.32.0 -tomlkit==0.5.8 -traitlets==4.3.3 -tzlocal==2.0.0 -urllib3==1.25.9 -virtualenv==16.2.0 -virtualenv-clone==0.5.4 -virtualenvwrapper==4.8.4 -wcwidth==0.1.9 -websocket-client==0.57.0 -Werkzeug==1.0.0 -whichcraft==0.6.1 -wrapt==1.12.1 -zipp==3.1.0