Skip to content

Java Maven Project running in multiple EC2 instances in AWS that uses various services such as SQS, Rekognition, S3 Bucket and EBS to perform image recognition.

Notifications You must be signed in to change notification settings

sprcoder/ImageRecognition

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

AWS_Simple_ImageRecognition

EC2 Instance Setup

  1. Created 2 EC2 instances in AWS, EC2-A & EC2-B
  2. Each Instace would have the following configuration while creating.
  • OS -> Amazon Linux 2 AMI 64 bit(x86)

image

  • Intance Type -> Selected the t2.micro that has free tier eligibility

image

  • Key Pair -> Created a new pair for using with my computer as MyMacConnect

image

  • Network Settings -> Created a setting with default values for ssh, http, https

  • Used the same setting for the 2 EC2 instances

  • Configure Storage -> Used the default free tier storage that was available for both the instances

image

  • Launch Instance -> With the below configurations, launched the EC2 instance

image

Running the Application

  1. Requires SQS setup before starting the application
  • Create a FIFO Queue for the instances to communicate

image

  1. EC2-A Instance
  • Connect to the EC2-A Instance using SSH

  • In the instance run aws configure

    • This would ask for the access key, id and session details that are available in the Learners Lab, AWS Details.
  • Once AWS is configured install java, I have used jdk-11.0.16.1_linux-x64_bin.rpm

  • After java installation, install maven, I have used apache-maven-3.9.0. Provided maven bin path to $PATH variable in linux to finalize installation.

  • Create a maven project with the following code

   mvn archetype:generate \
  -DarchetypeGroupId=software.amazon.awssdk \
  -DarchetypeArtifactId=archetype-app-quickstart \
  -DarchetypeVersion=2.18.16
  • Use the following configuration while creating the maven project

image

- Below is the structure of the generated project
├── src
│   ├── main
│   │   ├── java
│   │   │   └── package
│   │   │       ├── App.java
│   │   │       ├── DependencyFactory.java
│   │   │       └── Handler.java
│   │   └── resources
│   │       └── simplelogger.properties
│   └── test
│       └── java
│           └── package
│               └── HandlerTest.java
  • App.java: main entry of the application
  • DependencyFactory.java: creates the SDK client
  • Handler.java: you can invoke the api calls using the SDK client here.
  1. Handler.java holds the main code for my application, which are the following
  • S3 bucket initialization and accessing the S3Object. Used the bucket provided in the assignment njit-cs-643.
  • Passed the image value from S3Object to AWS Rekognition method that would identify the label of the image.
  • Image index that is identified as car with confidence more than 90 is sent as SQS message using the sqsClient & sendMessage to the queueurl of A-B.fifo.
  1. ImageRecog.java was created to hold the AWS Rekognition method.
  • This method creates a rekognitionClient and use the DetectLabelsRequest object to identify the labels in the image.
  1. Run the program by cleaning the mvn package and executing the package:
mvn clean package
mvn exec:java -Dexec.mainClass="org.example.App"
  • Please refer to output_a.txt in ec2_a_imgrecog.zip/imgRecog/ for the results of execution.
  1. EC2-B Instance
  • For the initial setup of the instance follow the step 2
  • Handler.java holds the main code for EC2-B instance application, which are the following
    • Checks for SQS messages from the FIFO queue A-B.fifo using ReceiveMessageRequest & sqsClient. Tries to get all messages with 20 attemps(As a exit condition, if no message is received from SQS)
    • Each request from a SQS message waits for 5 seconds to get the message.
    • Once message is received, index from the body of the message is retrieved. And the message is deleted using DeleteMessageRequest.
    • Passing the index of the image to AWS Rekognition method with the bucketname would retieve a list of texts that is found in the image.
    • The image information along with the text identified from the image is written into a file.
  • TextRecog.java was created to hold the AWS Rekognition method.
    • This method would get the image name, bucket name and using the rekognitionClient & DetectTextRequest identifies the text present in the image.
  • Follow the step 5 to run the application
    • Please refer to output_b.txt in ec2_b_imagerecog_textrecog.zip/imageRecog/ for the results of execution.

About

Java Maven Project running in multiple EC2 instances in AWS that uses various services such as SQS, Rekognition, S3 Bucket and EBS to perform image recognition.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages