The bucket serves as the central storage for:
-
Raw IoT traffic data uploaded by branches.
-
Summarized data produced by the SummarizeWorker Lambda function.
-
Consolidated results from the ConsolidatorWorker Lambda function.
-
Final data: exported by the Export Client.
-
Open Amazon S3:
-
Log in to your AWS Management Console.
-
From the Services menu, select S3 (Storage).
-
-
Create a New Bucket:
-
Click on Create bucket.
-
Configure the bucket with the following settings:
-
Bucket Name:
newbucket37920
. -
AWS Region:
us-east-1
.
-
-
Set Object Ownership:
- In the Object Ownership section, select ACLs enabled.
-
Enable Versioning:
- In the Bucket Versioning section, click Enable.
-
Finalize the Bucket Creation:
-
Leave all other settings as default.
-
Click Create bucket.
-
The UploadClient
automates the process of uploading IoT traffic files to the newbucket37920
S3 bucket. Files are organized by branch ID and date to facilitate traceability and scalability.
Before using the UploadClient
, ensure the following:
-
AWS CLI is installed and configured with valid credentials.
-
Java 17+ is installed.
-
Apache Maven is installed.
-
The S3 bucket
newbucket37920
is created and accessible.
- Clone the repository:
git clone https://github.com/ouad002
cd aws-cloud
- Build the Project
To compile and build the project, use the following Maven command:
mvn clean package
- Run the UploadClient
To upload a file to the S3 bucket using the UploadClient
, use the following command:
java -cp target/aws-project-cloud-1.0-SNAPSHOT.jar com.project.s3.UploadClient /mnt/c/Users/user/Downloads/data-20221201.csv
Use AWS Lambda for real-time processing of IoT traffic files. The SummarizeWorker and ConsolidatorWorker Lambda functions are triggered automatically when files are uploaded to the S3 bucket (newbucket37920
).
-
Open the AWS Lambda Console:
-
Log in to your AWS Management Console.
-
Navigate to the Lambda service.
-
-
Create a New Lambda Function:
- Click Create function.
- Choose Author from scratch and configure the function:
- Function Name:
SummarizeWorker
(repeat forConsolidatorWorker
). - Runtime: Java 11 or Java 17.
- Execution Role: Create or use an IAM role with the following permissions:
AmazonS3FullAccess
AWSLambdaBasicExecutionRole
CloudWatchLogsFullAccess
.
- Function Name:
- Click Create function.
-
Build the Project:
- Use Maven to generate the
.jar
file:mvn clean package
- The compiled
.jar
file will be located in thetarget/
directory.
- Use Maven to generate the
-
Upload the Code to Lambda:
- Go to the Lambda function in the AWS Console.
- In the Code section, click Upload from > .zip or .jar file.
- Upload the
aws-project-cloud-1.0-SNAPSHOT.jar
.
-
Add an S3 Trigger:
- Navigate to the Configuration > Triggers tab of the Lambda function.
- Click Add trigger and select S3.
- Configure the trigger:
- Bucket:
newbucket37920
. - Event type:
PUT
(trigger when a file is uploaded). - Prefix: Optionally, set a folder prefix (e.g.,
raw/
for input files).
- Bucket:
- Save the trigger.
-
Repeat the process for both
SummarizeWorker
andConsolidatorWorker
.
-
Upload a Test File:
- Use the
UploadClient
or the AWS Management Console to upload a sample.csv
file to thenewbucket37920
bucket.
- Use the
-
Check the Logs:
- Open Amazon CloudWatch Logs.
- Verify the logs for each Lambda function to ensure the file was processed successfully.
This section explains how to configure an EC2 instance and run the SummarizeWorker
Java application.
In this project, we use an AWS EC2 instance to run the Java application for processing IoT traffic files.
-
Open the AWS Management Console:
- Navigate to the EC2 Dashboard.
-
Create a New EC2 Instance:
- Click Launch Instance and configure as follows:
- Name:
project-cloud
. - AMI: Select Amazon Linux 2 or any Java-compatible OS.
- Instance Type: Choose
t2.micro
(free-tier eligible) or higher. - Key Pair: Select an existing key pair or create a new one for SSH access.
- Security Group: Configure inbound rules to allow:
- SSH: Port 22 (for connecting to the instance).
- Custom TCP: Port 8080 or any port your application requires.
- Name:
- Click Launch Instance.
- Click Launch Instance and configure as follows:
-
Connect to the EC2 Instance:
- Use the following commands to connect via SSH:
Replace
chmod 400 /home/user/project.pem ssh -i /home/user/project.pem ec2-user@ec2-54-174-115-182.compute-1.amazonaws.com
/home/user/project.pem
with the path to your.pem
key file andec2-54-174-115-182.compute-1.amazonaws.com
with your instance's public IP.
- Use the following commands to connect via SSH:
-
Install Java and Maven:
- Run these commands on the EC2 instance:
sudo dnf amazon-linux-extras enable corretto8 sudo dnf install java-11-amazon-corretto -y sudo yum install maven -y
- Run these commands on the EC2 instance:
Once the EC2 instance is configured, you can run the SummarizeWorker
Java application.
-
Build the Project on EC2:
- Upload the project files to the EC2 instance.
- Navigate to the project directory and build the application:
mvn clean package
- Confirm that the JAR file (
aws-project-cloud-1.0-SNAPSHOT.jar
) is located in thetarget/
directory.
-
Execute the SummarizeWorker:
- Run the following command:
java -cp target/aws-project-cloud-1.0-SNAPSHOT.jar com.project.lambda.SummarizeWorkerApp
- Run the following command:
-
Verify the Results:
- Check the EC2 console output to ensure successful processing.
- Verify the processed file in the S3 bucket, if applicable.
This completes the configuration and running of the SummarizeWorker
on AWS EC2.
To run the program, use the following command in the project directory:
java -cp target/aws-project-cloud-1.0-SNAPSHOT.jar com.project.s3.ExportClient
- The files are merged and exported into a CSV file named exported_combined_summary.csv in the current directory.
- The date used to filter files is set by default in the code (e.g., "2025-01-11"). To change the date, update the main method in the ExportClient.java file.