DEV Community

Cover image for Interview Questions on AWS EC2 and Compute Services
Sushant Gaurav
Sushant Gaurav

Posted on

Interview Questions on AWS EC2 and Compute Services

1. What is AWS EC2, and how does it work?

Answer:

AWS EC2 (Elastic Compute Cloud) is a web service that provides scalable virtual servers in the cloud. You can use EC2 to launch instances with your desired operating system, CPU, memory, and storage configurations.

Example Explanation:

Imagine you’re running an online store. During the holiday season, you expect traffic spikes. With EC2, you can launch additional instances to handle increased traffic and terminate them afterwards, ensuring cost efficiency.

2. What are the types of EC2 instance families?

Answer:

EC2 instances are categorized based on use cases:

  1. General Purpose (e.g., t3, m5): Balanced performance for web servers and development.
  2. Compute Optimized (e.g., c5): Ideal for compute-heavy tasks like high-performance computing.
  3. Memory Optimized (e.g., r5): Suited for applications requiring a large memory footprint, like in-memory databases.
  4. Storage Optimized (e.g., i3, d2): Best for tasks needing high disk throughput, like data warehousing.
  5. Accelerated Computing (e.g., p3, g4): Designed for GPU-based workloads, such as machine learning.

Example Explanation:

If you’re running a financial modelling application that needs high computing power, you’d use c5 instances. For a machine learning model requiring GPUs, go with p3 instances.

3. What is the difference between a Spot Instance and an On-Demand Instance?

Answer:

  • On-Demand Instances: Pay-as-you-go pricing with no long-term commitment.
  • Spot Instances: Use spare EC2 capacity at up to 90% discount but can be interrupted by AWS with two minutes’ notice.

Example Explanation:

If you’re hosting a web application, use On-Demand Instances for consistent uptime. For batch processing, like rendering a 3D animation overnight, Spot Instances are cost-effective.

4. How do you monitor and troubleshoot EC2 instances?

Answer:

You can monitor EC2 instances using:

  1. CloudWatch: Tracks metrics like CPU utilization, memory usage, and network activity.
  2. CloudTrail: Logs API activity for security audits.
  3. EC2 Status Checks: Detect hardware or software issues.

Example Explanation:

If an instance shows high CPU utilization in CloudWatch, you can SSH into the instance and check running processes using top. If memory usage is also high, consider resizing the instance to a larger type.

5. How does EC2 Auto Scaling work?

Answer:

EC2 Auto Scaling automatically adjusts the number of EC2 instances based on demand using defined metrics (e.g., CPU utilization).

Example Explanation:

For an e-commerce website:

  • Set a scaling policy to add instances when CPU usage exceeds 70%.
  • Terminate instances when CPU usage drops below 30%. This ensures the site performs well during peak times while minimizing costs during low traffic.

6. What is the difference between Elastic Load Balancer (ELB) and Auto Scaling?

Answer:

  • ELB: Distributes incoming traffic across multiple EC2 instances to ensure even load distribution and fault tolerance.
  • Auto Scaling: Dynamically adds or removes EC2 instances to match workload demands.

Example Explanation:

Imagine a blog website with varying traffic. ELB ensures traffic is evenly spread across instances, while Auto Scaling ensures you always have the right number of instances to handle the traffic load.

7. How do you connect to an EC2 instance?

Answer:

You can connect to an EC2 instance using SSH.

  1. Ensure the Security Group allows inbound SSH traffic (port 22).
  2. Use a key pair file (e.g., my-key.pem).

Example Command:

ssh -i "my-key.pem" ec2-user@<instance-public-IP>
Enter fullscreen mode Exit fullscreen mode

Example Explanation:

Suppose you’ve launched a Linux EC2 instance. If the instance has a public IP of 13.56.78.90, you would connect using:

ssh -i "my-key.pem" ec2-user@13.56.78.90
Enter fullscreen mode Exit fullscreen mode

8. What is an AMI, and how do you create a custom AMI?

Answer:

An Amazon Machine Image (AMI) is a template used to create EC2 instances. It includes the OS, software, and configurations.

Steps to Create a Custom AMI:

  1. Launch an EC2 instance and configure it as needed.
  2. Go to the EC2 dashboard, select the instance, and choose “Create Image.”
  3. AWS will create an AMI from the instance.

Example Explanation:

If you frequently deploy web servers with specific configurations (e.g., Nginx installed, PHP configured), you can create a custom AMI for quicker deployment.

9. What is the difference between EBS and Instance Store?

Answer:

  • EBS (Elastic Block Store): Persistent block storage attached to EC2 instances. Data persists even after the instance is stopped.
  • Instance Store: Temporary storage that is lost when the instance is stopped or terminated.

Example Explanation:

Use EBS for storing critical application data (e.g., a database). Use Instance Store for temporary files, such as cache or buffer storage, where data loss is acceptable.

10. How do you secure an EC2 instance?

Answer:

  1. Use IAM Roles to manage instance permissions instead of embedding credentials in the code.
  2. Configure Security Groups to allow only required inbound and outbound traffic.
  3. Regularly patch and update the OS.
  4. Use VPC for network isolation.

Example Explanation:

For a web server, you would:

  • Allow inbound HTTP (port 80) and HTTPS (port 443) traffic in the Security Group.
  • Block all unused ports and restrict SSH access to specific IP addresses.

11. What are EC2 Reserved Instances, and when would you use them?

Answer:

Reserved Instances offer a significant discount (up to 75%) compared to On-Demand Instances for long-term commitments (1 or 3 years).

Example Explanation:

If you have a database server that runs 24/7, a Reserved Instance ensures cost savings since the workload is predictable.

12. What is Elastic Beanstalk, and how does it simplify EC2 usage?

Answer:

Elastic Beanstalk is a Platform-as-a-Service (PaaS) that automatically handles the deployment, scaling, and management of your application.

Example Explanation:

Suppose you’re deploying a Python web app. With Elastic Beanstalk, you upload your code, and it takes care of provisioning EC2 instances, setting up load balancing, and managing scaling.

Conclusion

This article equips you with detailed and practical explanations for common AWS EC2 and compute service interview questions. In the next article, we’ll cover AWS Identity and Access Management (IAM) Interview Questions with real-world scenarios and examples.

Top comments (0)