Troubleshooting and Resource Cleanup
This article covers the order for finding the cause when a connection fails, how to clean up after a lab so no charges are incurred, and the limitations of the B3-1 setup.
Form a Hypothesis and Verify One at a Time
If you change settings here and there at random, you can't tell what the cause was, and it is hard to undo. So instead, look at the symptom, form candidate causes (hypotheses), and rule them out one by one with commands.
| Case | Symptom | Confirmed cause | Fix |
|---|---|---|---|
| External access failure | Browser can't connect, SSH works | No HTTP 80 rule in the security group | Added 80 inbound, included it in the script |
| SSH refused | Permission denied (publickey) | .pem file permission 644 | chmod 400, run automatically in the script |
| EC2 creation denied | UnauthorizedOperation | Partially blocked by the region condition in the IAM policy | Fixed the condition to allow only the needed range |
Checklist Order When External Access Fails
1. Routing: does the route table have 0.0.0.0/0 → IGW, and is it associated with the subnet?
2. Security group: is the port open in the inbound rules?
3. Public IP: does the instance have a public IP?
4. Server process: systemctl status nginx, curl localhost
5. Logs: /var/log/nginx/error.log, /var/log/syslogThis order narrows things down from the outside (network) to the inside (server). If SSH works but the web doesn't, routing and the public IP are fine, so you can start with the security group.
Resource Cleanup
On AWS, you can be charged just for resources being on or left behind. Resources that depend on each other must be deleted in the order below so that the parent resources can be deleted.
Terminate EC2 → clean up leftover EBS volumes and Elastic IPs → detach and delete the IGW
→ subnets → route tables → security groups → VPC → key pair| Things that can cost money if left behind | Reason |
|---|---|
| EC2 | For running time (once you exceed the free tier limit) |
| EBS volumes | If a volume remains after deleting the instance, charged for its size |
| Elastic IP, public IPv4 | Public IPv4 addresses are charged hourly |
| NAT gateways, load balancers | Charged hourly just for existing |
In B3-1, every resource was tagged with a name starting with cloud-lab-, and cleanup-infrastructure.sh used this tag to find what to delete and removed it in order. Finally, I checked in the billing dashboard that no more charges were accruing.
Limitations of the B3-1 Setup
- There is one server in one AZ. If that AZ or the server has a problem, the service stops. To survive failures, you need servers in multiple AZs tied together with a load balancer.
- The EC2 instance is directly exposed in a public subnet. In real-world setups, only the load balancer sits outside, and the servers go in private subnets.
- Only HTTP is used. There is no domain or HTTPS certificate, so the traffic is not encrypted.
- The public IP can change. It is an auto-assigned IP, so stopping and starting the instance changes the address. There is no Elastic IP or domain.
- It is managed through SSH port 22 and a key file. It is restricted to my IP, but there are also options like Session Manager that don't open the port at all.
- Shell scripts don't remember state. Running
setup-infrastructure.shagain creates the same resources again. IaC tools like Terraform compare against the current state and apply only what changed. - IAM permissions are narrowed only at the action level. Most are
Resource: "*", so other VPCs or instances could also be touched. Also, the troubleshooting document says the region condition was fixed, but theec2:Regioncondition is still insetup-iam.shin the repository. - There is no monitoring or log collection. No alert comes if the server dies, and you have to log into the server directly to see the logs.
Interview Questions
Q. If a web server on EC2 can't be reached from outside, in what order do you check?
This checks whether you have a systematic order for narrowing down the cause from the symptom.
I check from the outside in. I confirm that the route table has an IGW route and is associated with the subnet, that port 80 is open in the security group's inbound rules, and that the instance has a public IP. Then I log into the server and check whether Nginx is running, whether
curl localhostworks, and look at the error log. In B3-1, SSH worked but the web didn't, so I started with the security group and found that the port 80 rule was missing.
Follow-up Questions
- Why does the order matter when deleting resources? → Just as a VPC can't be deleted while subnets or security groups remain inside it, a parent resource can't be deleted while resources that depend on it still exist.
- If you were turning this setup into a real service, what would you change first? → I would split the servers across private subnets in two AZs and have a load balancer in the public subnet accept HTTPS. I would move the infrastructure to IaC such as Terraform.
Source: Codyssey-B1/B3-1
