Extract data from an Image

Ruchita Patel
3 min readJan 31, 2021

Prerequisite:

Amazon Account

Services Used:

  1. Amazon API Gateway
  2. Amazon Lambda
  3. Amazon Textract
  4. Amazon S3

Steps to implement

  1. Create a website which will upload an image to S3 bucket and print the result on webpage.
  2. Create a lambda function to get the Presigned URL and store an image to S3 bucket.
  3. Create an API Gateway for get and post request.
  4. Create a lambda function which will be triggered when user upload an image to S3 bucket. Call Amazon Textract API which will take an image and extract data from an image and give a response to the lambda function. Lambda function will then store the extracted data to S3 bucket.
  5. Create a lambda function which will be triggered when user wants to get the data from an image.

To create an API Gateway:

Create an API for post Request:

  1. Click on create API. Select REST API. Give a name and Click on Create API.
  2. To create a method Click on Actions -> Create Method -> Select POST.
  3. Select Integration type: Lambda function, Your region and choose your lambda function then Save.
  4. Enable CORS.

5. Finally Deploy API. Copy API url and paste it in your code .

Create another API for get request:

  1. Click on create API. Select REST API. Give a name and Click on Create API.
  2. To create a method Click on Actions -> Create Method -> Select GET.
  3. Select Integration type: Lambda function, Your region and choose your lambda function then Save.
  4. Set “key” as your Query String Parameter and change Request Validator.

5. Define Mapping Template

Click on Save.

6. Enable CORS.

7. Deploy API and paste url in your code.

To create a IAM role:

  1. Create Role.
  2. Attach following policies:

AWSLambdaBasicExecutionRole

AmazonS3FullAccess

CloudWatchFullAccess

AmazonTextractFullAccess

3. Attach created role to the lambda function.

Finally we have done all the AWS side Configuration and Creation. And now Upload code to the S3 bucket to access your Website.

To upload code into S3 bucket:

  1. Create a bucket and upload your code files to the bucket.
  2. Select files and make them public. So, everyone can access your website.

Actions -> Make public

3. Click on Permissions and set CORS.

4. Click on HTML file, Copy Object URL and paste it in Browser.

--

--