1. What is AWS VPC, and why is it important?
Answer:
AWS VPC (Virtual Private Cloud) is a logically isolated network within the AWS cloud where you can launch your AWS resources securely. It allows you to define your IP address ranges, create subnets, configure route tables, and set up internet access through gateways.
Example Explanation:
Think of a VPC as your private office building in the AWS cloud. Within the office (VPC), you can have separate rooms (subnets) for different departments, like public-facing services (e.g., a website) and private services (e.g., a database). You control who can enter or exit each room (using Security Groups and Network ACLs).
2. What is the difference between stateful and stateless firewalls?
Answer:
A stateful firewall keeps track of the state of active connections, automatically allowing return traffic. A stateless firewall, on the other hand, treats each request independently and requires explicit rules for both incoming and outgoing traffic.
Example Explanation:
- Stateful (Security Groups): Imagine a hotel check-in system where guests can leave freely once they enter. For example, if you allow HTTP traffic to an instance, return HTTP responses are automatically permitted.
- Stateless (NACL): It’s like a building security gate where you must scan your ID both when entering and exiting, as it doesn’t remember you.
Feature | Security Groups (Stateful) | NACLs (Stateless) |
---|---|---|
Operates on | Instance level | Subnet level |
Stateful/Stateless | Stateful | Stateless |
Rule Types | Allow rules only | Allow and deny rules |
3. How does traffic flow in a VPC?
Answer:
Traffic in a VPC flows through the following components:
- Route Tables: Direct traffic between subnets, internet gateways, and NAT gateways.
- Internet Gateway (IGW): Allows resources in a VPC to communicate with the internet.
- Network ACLs and Security Groups: Apply rules to manage traffic permissions.
Example Explanation:
Suppose you have a public-facing web application. The traffic flow would look like this:
- A user’s request first hits the Internet Gateway, which routes it to the appropriate subnet (public or private) based on the route table.
- The Security Group on the EC2 instance evaluates whether to allow the request (e.g., HTTP on port 80).
- If the instance needs to call an external API, the request is routed back through a NAT Gateway in the public subnet.
4. How would you design a VPC for a 2-tier application?
Answer:
For a 2-tier architecture:
- Public Subnet: For hosting a Load Balancer or NAT Gateway.
- Private Subnet: For application servers and databases.
- Distribute subnets across multiple Availability Zones for redundancy.
- Use Security Groups to allow only HTTP/HTTPS traffic to the Load Balancer and internal traffic to the application servers.
Example Explanation:
Imagine hosting an e-commerce website. The Load Balancer is like the storefront where customers interact, placed in the public subnet. The application servers (processing orders) and the database (storing order details) are placed in private subnets to ensure security. Using an Auto Scaling Group, the application layer automatically adjusts based on customer demand.
5. How can you restrict outbound internet access for a specific subnet?
Answer:
To restrict outbound internet access:
- Remove the route pointing to
0.0.0.0/0
(default route) in the subnet's route table. - Ensure no NAT Gateway or NAT instance is associated with the subnet.
Example Explanation:
Suppose you have sensitive workloads, like a database server, in a private subnet. By removing the outbound route, you ensure that the database cannot access the internet directly, thus preventing accidental data leaks. However, for necessary updates or external communications, you can configure access through a bastion host.
6. How do you allow instances in a private subnet to access the internet?
Answer:
Use a NAT Gateway:
- Place the NAT Gateway in a public subnet.
- Configure the route table of the private subnet to direct outbound traffic (
0.0.0.0/0
) to the NAT Gateway.
Example Explanation:
Consider a private subnet hosting application servers that need to fetch updates from external APIs. The NAT Gateway acts as a middleman, allowing these instances to send requests to the internet without exposing them to incoming traffic.
7. What is a Load Balancer, and how is it used in AWS?
Answer:
A Load Balancer distributes incoming traffic across multiple targets, such as EC2 instances, containers, or IP addresses, ensuring better fault tolerance and high availability.
Example Explanation:
Think of a Load Balancer as the cashier counter in a busy supermarket. When customers (traffic) arrive, the Load Balancer ensures they are evenly distributed among all available cashiers (instances) so no single cashier is overwhelmed.
AWS offers three types of Load Balancers:
- Application Load Balancer (ALB): Handles HTTP/HTTPS traffic, allowing path-based and host-based routing.
- Network Load Balancer (NLB): Operates at Layer 4 for ultra-low latency traffic, such as financial applications.
- Classic Load Balancer (CLB): Legacy option for both Layer 4 and Layer 7 routing.
8. How do Auto Scaling Groups (ASG) work?
Answer:
ASGs automatically adjust the number of EC2 instances based on demand. They use:
- Scaling Policies: Add or remove instances based on metrics like CPU utilization.
- Health Checks: Terminate and replace unhealthy instances.
Example Explanation:
Imagine running a news website that experiences a traffic surge during major events. Using an ASG, the system can automatically launch more EC2 instances during peak traffic and scale down during quiet hours, saving costs.
9. How would you combine VPC, Load Balancers, and ASGs for a scalable architecture?
Answer:
Here’s how to create a scalable architecture:
- Create a VPC with public and private subnets in multiple AZs.
- Place a Load Balancer in the public subnet to distribute traffic.
- Deploy application servers in the private subnets using an Auto Scaling Group to handle dynamic scaling.
- Use a NAT Gateway for instances in private subnets to access external resources.
Example Explanation:
Suppose you’re designing a video-streaming platform. The Load Balancer ensures users are connected to the least busy server, while the ASG ensures you have enough instances to handle a sudden increase in viewers.
10. How do NACLs and Security Groups complement each other?
Answer:
While Security Groups control access at the instance level, NACLs provide an additional layer of subnet-level security.
Example Explanation:
Think of NACLs as the outer gate of an apartment complex, controlling access to the building (subnet). Security Groups, on the other hand, are like individual apartment locks, ensuring that only authorized guests can enter specific rooms (instances).
Conclusion
This style ensures you’re ready for technical interviews with real-world examples to back up your answers. In the next article, we’ll dive into AWS EC2 and Compute Services interview questions with detailed explanations.
Top comments (0)