You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# AWS EC2 Auto Deployment with Terraform & Shell Scripts
2
2
3
-
This project automates the provisioning of an EC2 instance and the deployment of your application on AWS using Terraform and shell scripts. It supports different environments (Dev, Prod) through configuration files and scripts.
3
+
This project automates the provisioning of an EC2 instance and the deployment of your application on AWS using Terraform and shell scripts. It supports different environments (Dev, Prod) through configuration files and deployment scripts.
4
4
5
5
---
6
6
@@ -9,50 +9,58 @@ This project automates the provisioning of an EC2 instance and the deployment of
- Shuts down the instance after 10-15 minutes (configurable)
131
+
### Shell Scripts:
132
+
- Update operating system packages.
133
+
- Install required tools such as Java, Git, Maven, AWS CLI, etc.
134
+
- Clone, build, and run the application on Port 80.
135
+
- Upload logs to the S3 bucket.
110
136
111
137
---
112
138
113
-
## ✅ **Security Notes**
139
+
## Note on Pulling Logs from EC2 to Local
140
+
141
+
To enable **log pulling from EC2 to your local machine,** follow these steps:
142
+
143
+
1.**Uncomment Lines in the Script:**
144
+
Locate the following lines in your deployment script between **lines 52–59** and uncomment them:
145
+
146
+
```bash
147
+
# Wait a while for logs to upload
148
+
sleep 100
149
+
cd .. # Save logs at the root level
150
+
PRIVATE_KEY_PATH="/Users/default/CS/DevOps/AWS/ssh-key-ec2.pem"# Change this to your SSH private key path and ensure `chmod 400` on your key
151
+
echo"Trying to SCP logs to local"
152
+
scp -r -i "$PRIVATE_KEY_PATH" ubuntu@$VERIFIER_IP:/mylogs/ .# Pull logs from EC2 to /mylogs/ in your local directory
153
+
cd$TERRAFORM_DIR# Return to Terraform directory for destroy commands
154
+
```
155
+
156
+
2.**Specify Your Private Key Path:**
157
+
- Replace the placeholder `"/Users/default/CS/DevOps/AWS/ssh-key-ec2.pem"` under the variable `PRIVATE_KEY_PATH` with the actual path to your EC2 key's private key file.
158
+
- Before using, ensure the private key has the appropriate permissions by running:
159
+
```bash
160
+
chmod 400 /path/to/your/private-key.pem
161
+
```
162
+
163
+
3. **Save the logs locally:**
164
+
After successfully setting this up, the script will pull logs from `/mylogs/` on your EC2 instance to a local`/mylogs/` directory at the repository's root level.
165
+
166
+
This addition ensures your logs are saved to your local environment automatically.
167
+
114
168
115
-
- No sensitive keys are stored in the repo
116
-
- Make sure your security group is restricted to specific IPs if used in production
117
-
- Rotate AWS credentials regularly
118
169
119
170
---
120
171
121
-
## 💬 **FAQ**
172
+
## 💬 **FAQs**
122
173
123
-
**Q: Can I deploy to a different AWS region?**
124
-
Yes. Modify the `aws_region`value in `terraform/variables.tf`, `dev_config.tfvars` and `prod_config.tfvars`
174
+
**Q: How can I deploy in a different region?**
175
+
Modify the `aws_region` variable in the `terraform/variables.tf` file and update it in the `.tfvars` files.
125
176
177
+
**Q: What happens if deployment fails?**
178
+
Terraform maintains a state file. Retry by running the deployment script again.
179
+
180
+
**Q: Where can I find the logs?**
181
+
Logs are stored in the `mylogs/` directory or uploaded to the configured S3 bucket.
2025-07-02T17:49:01.816Z INFO 4364 --- [techeazy-devops] [ main] c.t.devops.TecheazyDevopsApplication : Starting TecheazyDevopsApplication v0.0.1-SNAPSHOT using Java 21.0.7 with PID 4364 (/home/ubuntu/app/target/techeazy-devops-0.0.1-SNAPSHOT.jar started by root in /home/ubuntu/app)
12
+
2025-07-02T17:49:01.821Z INFO 4364 --- [techeazy-devops] [ main] c.t.devops.TecheazyDevopsApplication : No active profile set, falling back to 1 default profile: "default"
13
+
2025-07-02T17:49:04.140Z INFO 4364 --- [techeazy-devops] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 80 (http)
14
+
2025-07-02T17:49:04.185Z INFO 4364 --- [techeazy-devops] [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
0 commit comments