- Created 2 EC2 instances in AWS, EC2-A & EC2-B
- Each Instace would have the following configuration while creating.
- OS -> Amazon Linux 2 AMI 64 bit(x86)
- Intance Type -> Selected the t2.micro that has free tier eligibility
- Key Pair -> Created a new pair for using with my computer as MyMacConnect
-
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
- Launch Instance -> With the below configurations, launched the EC2 instance
- Requires SQS setup before starting the application
- Create a FIFO Queue for the instances to communicate
- 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
├── src
│ ├── main
│ │ ├── java
│ │ │ └── package
│ │ │ ├── App.java
│ │ │ ├── DependencyFactory.java
│ │ │ └── Handler.java
│ │ └── resources
│ │ └── simplelogger.properties
│ └── test
│ └── java
│ └── package
│ └── HandlerTest.java
App.java
: main entry of the applicationDependencyFactory.java
: creates the SDK clientHandler.java
: you can invoke the api calls using the SDK client here.
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 assignmentnjit-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 ofA-B.fifo
.
ImageRecog.java
was created to hold the AWS Rekognition method.
- This method creates a
rekognitionClient
and use theDetectLabelsRequest
object to identify the labels in the image.
- 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
inec2_a_imgrecog.zip/imgRecog/
for the results of execution.
- 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
usingReceiveMessageRequest
&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.
- Checks for SQS messages from the FIFO queue
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.
- This method would get the image name, bucket name and using the
- Follow the step 5 to run the application
- Please refer to
output_b.txt
inec2_b_imagerecog_textrecog.zip/imageRecog/
for the results of execution.
- Please refer to