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 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 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/InvokeTextract/SampleEvent.json b/invokeTarkovTextract/SampleEvent.json similarity index 100% rename from InvokeTextract/SampleEvent.json rename to invokeTarkovTextract/SampleEvent.json 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 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