Skip to content

Commit 1c8b83e

Browse files
committed
Using my own custom ami with pre-installed tools
1 parent b914ae4 commit 1c8b83e

File tree

8 files changed

+900
-889
lines changed

8 files changed

+900
-889
lines changed

mylogs/app/my-app.log

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
:: Spring Boot :: (v3.4.6)
1010

11-
2025-07-08T23:23:28.441Z INFO 4086 --- [techeazy-devops] [ main] c.t.devops.TecheazyDevopsApplication : Starting TecheazyDevopsApplication v0.0.1-SNAPSHOT using Java 21.0.7 with PID 4086 (/home/ubuntu/app/target/techeazy-devops-0.0.1-SNAPSHOT.jar started by root in /home/ubuntu/app)
12-
2025-07-08T23:23:28.445Z INFO 4086 --- [techeazy-devops] [ main] c.t.devops.TecheazyDevopsApplication : No active profile set, falling back to 1 default profile: "default"
13-
2025-07-08T23:23:30.381Z INFO 4086 --- [techeazy-devops] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 80 (http)
14-
2025-07-08T23:23:30.411Z INFO 4086 --- [techeazy-devops] [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
15-
2025-07-08T23:23:30.411Z INFO 4086 --- [techeazy-devops] [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.41]
16-
2025-07-08T23:23:30.612Z INFO 4086 --- [techeazy-devops] [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
17-
2025-07-08T23:23:30.615Z INFO 4086 --- [techeazy-devops] [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2078 ms
18-
2025-07-08T23:23:31.650Z INFO 4086 --- [techeazy-devops] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port 80 (http) with context path '/'
19-
2025-07-08T23:23:31.676Z INFO 4086 --- [techeazy-devops] [ main] c.t.devops.TecheazyDevopsApplication : Started TecheazyDevopsApplication in 4.078 seconds (process running for 4.942)
11+
2025-07-09T02:15:37.428Z INFO 1021 --- [techeazy-devops] [ main] c.t.devops.TecheazyDevopsApplication : Starting TecheazyDevopsApplication v0.0.1-SNAPSHOT using Java 21.0.7 with PID 1021 (/home/ubuntu/app/target/techeazy-devops-0.0.1-SNAPSHOT.jar started by root in /home/ubuntu/app)
12+
2025-07-09T02:15:37.434Z INFO 1021 --- [techeazy-devops] [ main] c.t.devops.TecheazyDevopsApplication : No active profile set, falling back to 1 default profile: "default"
13+
2025-07-09T02:15:39.092Z INFO 1021 --- [techeazy-devops] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 80 (http)
14+
2025-07-09T02:15:39.129Z INFO 1021 --- [techeazy-devops] [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
15+
2025-07-09T02:15:39.130Z INFO 1021 --- [techeazy-devops] [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.41]
16+
2025-07-09T02:15:39.384Z INFO 1021 --- [techeazy-devops] [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
17+
2025-07-09T02:15:39.387Z INFO 1021 --- [techeazy-devops] [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1866 ms
18+
2025-07-09T02:15:40.741Z INFO 1021 --- [techeazy-devops] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port 80 (http) with context path '/'
19+
2025-07-09T02:15:40.779Z INFO 1021 --- [techeazy-devops] [ main] c.t.devops.TecheazyDevopsApplication : Started TecheazyDevopsApplication in 4.164 seconds (process running for 4.981)

mylogs/system/cloud-init.log

Lines changed: 829 additions & 832 deletions
Large diffs are not rendered by default.

scripts/deploy.sh

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ terraform init
2424
echo "[+] Applying configuration for environment: $ENV"
2525
terraform apply -var-file="$CONFIG_FILE" -auto-approve
2626

27-
echo "[+] Waiting 200 seconds for app to deploy in ec2 instance"
28-
sleep 200
27+
echo "[+] Waiting 30 seconds for app to deploy in ec2 instance"
28+
sleep 30
2929

3030
# Get the public IP from Terraform output
3131
RAW_INSTANCE_IP=$(terraform output -raw instance_public_ip)
@@ -49,14 +49,14 @@ VERIFIER_IP=$(terraform output -raw verifier_instance_public_ip)
4949
echo "Verified Public IP: $VERIFIER_IP"
5050

5151

52-
# #To verify and pull logs from ec2 to local.
53-
# echo "Wait 2min for verifier ec2 (read only) to pull the logs from s3 to local environment"
54-
# sleep 120
55-
# cd .. # to save logs at root level
56-
# PRIVATE_KEY_PATH="/Users/default/CS/DevOps/AWS/ssh-key-ec2.pem" #change this to your ssh private key path, also make sure to use `chmod 400` on your key before using
57-
# echo "trying to scp logs to local"
58-
# scp -r -i "$PRIVATE_KEY_PATH" -o StrictHostKeyChecking=no ubuntu@$VERIFIER_IP:/mylogs/ . #to pull logs from readonly ec2 to your local directory /mylogs/
59-
# cd $TERRAFORM_DIR # to run destroy need to go to terraform directory
52+
#To verify and pull logs from ec2 to local.
53+
echo "Wait 100 seconds for verifier ec2 (read only) to pull the logs from s3 to local environment"
54+
sleep 100
55+
cd .. # to save logs at root level
56+
PRIVATE_KEY_PATH="/Users/default/CS/DevOps/AWS/ssh-key-ec2.pem" #change this to your ssh private key path, also make sure to use `chmod 400` on your key before using
57+
echo "trying to scp logs to local"
58+
scp -r -i "$PRIVATE_KEY_PATH" -o StrictHostKeyChecking=no ubuntu@$VERIFIER_IP:/mylogs/ . #to pull logs from readonly ec2 to your local directory /mylogs/
59+
cd $TERRAFORM_DIR # to run destroy need to go to terraform directory
6060

6161
echo -e "\n"
6262
echo "[+] Using curl on app at http://$RAW_INSTANCE_IP:80"
@@ -65,8 +65,8 @@ curl "http://$RAW_INSTANCE_IP:80"
6565
echo -e "\n"
6666
echo -e "\n"
6767

68-
echo "Terraform destroy will run after 2 minutes..."
68+
echo "Terraform destroy will run after 5 minutes..."
6969
echo "You can press ctrl+c and do it earlier as well"
70-
sleep 120
70+
sleep 300
7171

72-
terraform destroy -var-file="$CONFIG_FILE" -auto-approve
72+
TF_LOG=DEBUG terraform destroy -var-file="$CONFIG_FILE" -auto-approve

scripts/dev_script.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33

44
# Update system and install dependencies
5-
apt-get update -y
6-
apt-get install -y unzip git openjdk-21-jdk maven
5+
# apt-get update -y
6+
# apt-get install -y unzip git openjdk-21-jdk maven
77

8-
# Install AWS CLI v2
9-
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
10-
unzip awscliv2.zip
11-
sudo ./aws/install
8+
# # Install AWS CLI v2
9+
# curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
10+
# unzip awscliv2.zip
11+
# sudo ./aws/install
1212

1313

1414
# Set JAVA_HOME

scripts/verify_logs_script.sh

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/bin/bash
22

33
# Install AWS CLI and dependencies
4-
apt-get update -y
5-
apt-get install -y unzip curl
4+
# apt-get update -y
5+
# apt-get install -y unzip curl
66

7-
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
8-
unzip awscliv2.zip
9-
sudo ./aws/install
7+
# curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
8+
# unzip awscliv2.zip
9+
# sudo ./aws/install
1010

1111
# Create directories for logs
1212
# cd /home/ubuntu
@@ -22,20 +22,34 @@ echo "Fetching logs from S3 Bucket: ${s3_bucket_name}"
2222
# sudo aws s3 sync s3://${s3_bucket_name} /mylogs/
2323

2424
echo "Waiting for logs to appear in S3 bucket: ${s3_bucket_name}"
25-
sleep 100
26-
MAX_RETRIES=20
27-
RETRY_DELAY=30 # seconds
28-
29-
for ((i=1; i<=MAX_RETRIES; i++)); do
30-
echo "Attempt $i: Syncing logs from S3..."
31-
if sudo aws s3 sync s3://${s3_bucket_name} /mylogs; then
32-
echo "Logs synced successfully on attempt $i"
33-
break
34-
else
35-
echo "Attempt $i failed. Waiting $RETRY_DELAY seconds before retrying..."
36-
sleep $RETRY_DELAY
37-
fi
38-
done
25+
sleep 60 # Its taking approx 60 seconds for app to run and logs to be sent in s3 from another ec2
26+
27+
sudo aws s3 sync s3://${s3_bucket_name} /mylogs
28+
29+
# MAX_RETRIES=20
30+
# RETRY_DELAY=30 # seconds
31+
32+
# for ((i=1; i<=MAX_RETRIES; i++)); do
33+
# echo "Attempt $i: Syncing logs from S3..."
34+
35+
# if sudo aws s3 sync s3://${s3_bucket_name} /mylogs; then
36+
# echo "S3 sync completed."
37+
38+
# # Check if both /mylogs/app and /mylogs/system exist and are not empty
39+
# if [ -d "/mylogs/app" ] && [ -n "$(ls -A /mylogs/app 2>/dev/null)" ] && \
40+
# [ -d "/mylogs/system" ] && [ -n "$(ls -A /mylogs/system 2>/dev/null)" ]; then
41+
# echo "✅ Both 'app' and 'system' logs found on attempt $i."
42+
# break
43+
# else
44+
# echo "⚠️ One or both directories missing or empty. Retrying..."
45+
# fi
46+
47+
# else
48+
# echo "❌ S3 sync failed. Retrying..."
49+
# fi
50+
51+
# sleep $RETRY_DELAY
52+
# done
3953

4054

4155

terraform/dev_config.tfvars

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
instance_type = "t2.micro"
2-
key_name = "ssh-key-ec2" #change this to your key-pair name
3-
ami_id = "ami-0f918f7e67a3323f0"
1+
instance_type = "t2.micro"
2+
key_name = "ssh-key-ec2" #change this to your key-pair name
3+
# ami_id = "ami-0f918f7e67a3323f0"
44
stage = "Dev"
55
shutdown_minutes = 30
66
s3_bucket_name = "techeazy-logs-dev-unique123ss" # Change this!

terraform/prod_config.tfvars

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
instance_type = "t2.micro"
2-
key_name = "ssh-key-ec2" #change this to your key-pair name
3-
ami_id = "ami-0f918f7e67a3323f0"
1+
instance_type = "t2.micro"
2+
key_name = "ssh-key-ec2" #change this to your key-pair name
3+
# ami_id = "ami-0f918f7e67a3323f0"
44
stage = "prod"
55
shutdown_minutes = 25
66
s3_bucket_name = "techeazy-logs-dev-unique123ss" # Change this!

terraform/variables.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ variable "aws_region" {
33
description = "AWS Mumbai region"
44
}
55
variable "ami_id" {
6-
# default = "ami-0d03cb826412c6b0f"
7-
# description = "AMI ID for Amazon Linux 2023"
8-
default = "ami-0f918f7e67a3323f0"
9-
description = "AMI ID for Ubuntu 24"
6+
# default = "ami-0f918f7e67a3323f0"
7+
#description = "AMI ID for Ubuntu 24"
8+
default = "ami-00cb641b494eae1e8" #my own ec2 ami with pre installed tools
9+
description = "Using own custom ec2 ami with pre installed aws cli v2, java 21, git, maven, curl"
1010
}
1111
variable "instance_type" {
1212
description = "EC2 instance type"

0 commit comments

Comments
 (0)