top of page

Tutorial to build serverless application that processes object-creation events in Amazon S3.

Tutorial to build serverless application that processes object-creation events in Amazon S3.


Tutorial Objectives:

1. Learn to create and configure Lambda function that detects object creation event in S3 & processes the same.

2. Learn to use Amazon Rekognition to detect text in an image & stores the same in DynamoDB table.


Step 1: Cloud9 operates in some specific regions for now. So, we have to switch to one of those operative Regions.

In AWS Console, top blue bar, from region drop down, select US East (N. Virginia) us-east-1.


Step 2: Go to Cloud9 Service. Click on Create Environment.

Provide the following configuration:

· Environment Name: MyCloud9

· Description: Cloud9 IDE for CloudPlusPlus Tutorial

Go to Next Step. Confirm the following list of default selected choices:

· Environment type: Create a new EC2 instance for environment (direct access)

· Instance type: t2.micro (1 GiB RAM + 1 vCPU)

· Platform: Amazon Linux 2 (recommended)

Proceed to Next Step. Review and click on Create environment.


Step 3: You will have the Cloud9 IDE ready in some time. A window as below is visible.

In the bottom part of the screen, a Terminal Window is visible. If not go to the Window option in Menu Bar of Cloud9 IDE and click on New Terminal.


Step 4: Download S3 Object Rekognition Application.zip from here into your local machine which consists of an AWS SAM template and application code.

· Once the environment is up and running, Click on the File->Upload local files…

And select the downloaded sample-application.zip file and click upload.

Right click on the cloud9 folder, and choose new folder.

Create a new folder and named it as aws_sam_ocr.

Run the following command to unzip the sample-application.zip file.

unzip sample-application.zip -d aws_sam_ocr

Step 5: Create Lambda deployment package

1. Run the following command to change the directory to aws_sam_ocr.

cd aws_sam_ocr/

2. Create an S3 bucket in the location where you want to save the packaged code.

aws s3 mb s3://deployement-pkg-bucket

here, deployement-pkg-bucket is the S3 bucket name.

Open S3 service in another console and check if bucket is created.

3. To create a deployment package run the following command

sam package \
    --template-file template.yaml \
    --output-template-file packaged.yaml \
    --s3-bucket deployement-pkg-bucket 

Step 6: Deploy the application

use the deploy command to deploy all of the resources that defined in the template.

sam deploy \
    --template-file packaged.yaml \
    --stack-name aws-sam-ocr \
    --capabilities CAPABILITY_IAM \
    --region us-east-1

AWS CloudFormation creates the AWS resources that are defined in the template.

You can access the names of these resources in the AWS CloudFormation console.


Step 7: To test the serverless application in the AWS Cloud

· Upload an image to the Amazon S3 bucket that you created for this sample application.

Uploaded image:

· Open the DynamoDB console and find the table that was created. See the table for results returned by Amazon Rekognition.

· Verify that the DynamoDB table contains new records that contain text that Amazon Rekognition found in the uploaded image.

Step 8: If you no longer need the Resources, you may delete it.

· Go to AWS CloudFormation service and delete the Stacks, DynamoDB table.

· Delete the Buckets.

· Delete Cloud9 environment.


Was this document helpful? How can we make this document better? Please provide your insights. You can download PDF version for reference.

Process Amazon S3 events
.pdf
Download PDF • 745KB

We provide the best AWS training from Pune, India.

For AWS certification, contact us now.

201 views8 comments

8 Comments


Very easy to understand the concept to building a serverless application to handle S3 events is clear .

Like

Atchaya B
Atchaya B
Apr 08

Helpful for building a serverless application to handle S3 events easier than expected

Like

Easy to understand the concept

Like

Gokulnath
Gokulnath
Apr 08

building a serverless application to handle S3 events is clear .


Like

This blog made building a serverless application to handle S3 events easier than expected. Very helpful.

Like
bottom of page