Skip to content

Instantly share code, notes, and snippets.

View SumindaD's full-sized avatar

Suminda Niroshan SumindaD

  • 1BillionTech
  • Colombo, Sri Lanka
View GitHub Profile
import json
import boto3
import os
dynamodb = boto3.client('dynamodb')
def handle(event, context):
connectionId = event['requestContext']['connectionId']
# Insert the connectionId of the connected device to the database
import boto3
import json
from boto3.dynamodb.conditions import Key, Attr
def lambda_handler(event, context):
eventBody = json.loads(json.dumps(event))['body']
searchString = json.loads(eventBody)['Search']
import json
import boto3
import os
def getJobResults(jobId):
pages = []
textract = boto3.client('textract')
response = textract.get_document_text_detection(JobId=jobId)
import json
import urllib.parse
import boto3
import os
def handle(event, context):
print("Triggered getTextFromS3PDF event: " + json.dumps(event, indent=2))
# Get the object from the event and show its content type
bucket = event['Records'][0]['s3']['bucket']['name']
service: textract-ocr-service
custom:
currentStage: ${opt:stage, self:provider.stage}
s3BucketName: textractbucket-#{AWS::AccountId}-${self:custom.currentStage}
snsTopicName: pdfExtractionDone-#{AWS::AccountId}-${self:custom.currentStage}
snsFullAccessRoleName: AwsSnsFullAccessRole-#{AWS::AccountId}-${self:custom.currentStage}
lambdaRunTime: python3.7
provider:
resources:
Resources:
snsAccessRole:
Type: AWS::IAM::Role
Properties:
RoleName: ${self:custom.snsFullAccessRoleName}
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AmazonSNSFullAccess
AssumeRolePolicyDocument:
Statement:
functions:
pdfgetjobresult:
handler: pdf_extract_result.handle
layers:
- { Ref: Boto3LayerLambdaLayer }
events:
- sns:
topicName: ${self:custom.snsTopicName}
displayName: Pdf Extraction Done SNS
pdfextractstart:
layers:
boto3Layer:
path: lib/boto3
name: boto3-layer
description: Boto3 layer for stage
compatibleRuntimes:
- ${self:custom.lambdaRunTime}
plugins:
- serverless-pseudo-parameters
provider:
name: aws
iamManagedPolicies:
- arn:aws:iam::aws:policy/AmazonSNSFullAccess
- arn:aws:iam::aws:policy/AmazonTextractFullAccess
- arn:aws:iam::aws:policy/AmazonS3FullAccess
runtime: ${self:custom.lambdaRunTime}
versionFunctions: false
region: us-east-1