WTf is an AWS Instance ?

WTf is an AWS Instance ?

What is it?

An Amazon Elastic Compute Cloud (EC2) instance is a virtual server that runs on Amazon Web Services (AWS) Cloud. With EC2, you can launch as many virtual machines (VMs) as you need, configure security and networking, and manage storage.

EC2 instances provide a wide variety of instance types optimized to fit different use cases, applications, and workloads. You can choose from General Purpose, Compute Optimized, Memory Optimized, Storage Optimized, GPU Instances, and ARM Instances.

To launch an EC2 instance, you need to select an Amazon Machine Image (AMI) that contains the necessary software configuration for your application. After that, you choose an instance type, configure instance details, add storage, and set up security.

EC2 instances are charged per hour and the pricing varies according to the instance type and region. You can also use Auto Scaling to automatically adjust your EC2 capacity based on demand.

Overall, EC2 instances provide scalable, reliable, and secure compute capacity on the AWS Cloud

AMI

An Amazon Machine Image (AMI) is a pre-configured virtual machine image that is used to create EC2 instances. AMIs include a pre-installed operating system, application server, and other necessary software. You can either choose from the available public AMIs or create your own custom AMI with your own configuration and software stack.

What Is the Relationship Between AMIs and EC2 Instances?

EC2 instances are live instantiations of what is defined in an AMI, much like a cake is a live instantiation of a cake recipe. If you are familiar with software development, you can also see this kind of relationship between a Class and an Object.

A Class is something you model and define, while an object is something you interact with. In this case, the AMI is how you model and define your instance, while the EC2 instance is the entity you interact with, where you can install your web server, and serve your content to users. When you launch a new instance, AWS allocates a virtual machine that runs on a hypervisor. Then the AMI you selected is copied to the root device volume, which contains the image used to boot the volume. In the end, you get a server you can connect to and install packages and any additional software. In this case, you install a web server along with the properly configured source code of your employee directory app.

If you wanted to create a second EC2 instance with the same configurations, how can you easily do that? One option is to go through the entire instance creation and configuration process and try to match your settings to the first instance. However, this is time consuming and leaves room for human error.

The second, better option, is to create an AMI from your running instance and use this AMI to start a new instance. This way, your new instance will have all the same configurations as your current instance, because the configurations set in the AMIs are the same.

EC2 instances are a combination of virtual processors (vCPUs), memory, network, and in some cases, instance storage and graphics processing units (GPUs). When you create an EC2 instance, you need to choose how much you need of each of these components.

AWS offers a variety of instances that differ based on performance. Some instances provide you with more capacity and others provide less. To get an overview of the capacity details for a particular instance, you should look at the instance type. Instance types consist of a prefix identifying the type of workloads they’re optimized for, followed by a size. For example, the instance type c5.large can be broken down into the following elements.

  • c5 determines the instance family and generation number. Here, the instance belongs to the fifth generation of instances in an instance family that’s optimized for generic computation.

  • large, which determines the amount of instance capacity.

Where Does Your EC2 Instance Live?

By default, your EC2 instances are placed in a network called the default Amazon Virtual Private Cloud (VPC). This network was created so that you can easily get started with Amazon EC2 without having to learn how to create and configure a VPC. Any resource you put inside the default VPC will be public and accessible by the internet, so you shouldn’t place any customer data or private information inside of it.

EC2 Instance Lifecycle

When you launch an instance, it enters the pending state (1). When the instance is pending, billing has not started. At this stage, the instance is preparing to enter the running state. Pending is where AWS performs all actions needed to set up an instance, such as copying the AMI content to the root device and allocating the necessary networking components. When your instance is running (2), it's ready to use. This is also the stage where billing begins. As soon as an instance is running, you are then able to take other actions on the instance, such as reboot , terminate , stop , and stop-hibernate . When you reboot an instance (3), it’s different than performing a stop action and then a start action. Rebooting an instance is equivalent to rebooting an operating system. The instance remains on the same host computer and maintains its public and private IP address, and any data on its instance store. It typically takes a few minutes for the reboot to complete. When you stop and start an instance (4), your instance may be placed on a new underlying physical server. Therefore, you lose any data on the instance store that were on the previous host computer. When you stop an instance, the instance gets a new public IP address but maintains the same private IP address. When you terminate an instance (5), the instance store are erased, and you lose both the public IP address and private IP address of the machine. Termination of an instance means you can no longer access the machine.

EC2 instances have four lifecycle states: pending, running, stopping, and stopped. When you first launch an instance, it enters the pending state while it’s being initialized. Once it’s ready to use, it enters the running state. When you stop an instance, it enters the stopping state before it enters the stopped state. In the stopping state, any data stored in the instance is flushed to the EBS root volume before it’s shut down. In the stopped state, the instance is no longer running and does not incur charges, but the EBS root volume is still available and can be used to launch a new instance.

What Is the Difference Between Stop and Stop-Hibernate?

When you stop your instance, it enters the stopping state, and then the stopped state. AWS does not charge usage or data transfer fees for your instance after you stop it, but storage for any Amazon EBS volumes is still charged. While your instance is in the stopped state, you can modify some attributes, like the instance type. When you stop your instance, the data stored in memory (RAM) is lost. When you stop-hibernate your instance, AWS signals the operating system to perform hibernation (suspend-to-disk), which saves the contents from the instance memory (RAM) to the Amazon EBS root volume.

Roles and Groups

AWS (Amazon Web Services) is a cloud computing platform that provides a wide range of services, including compute, storage, and database services. EC2 (Elastic Compute Cloud) is one of the key services offered by AWS, providing scalable virtual server capacity in the cloud. With EC2, users can launch virtual machines (VMs) and configure them to fit their specific needs, including selecting an instance type optimized for their workload. AMIs (Amazon Machine Images) are pre-configured virtual machine images that can be used to create EC2 instances, either from available public AMIs or by creating a custom AMI with the user's own software configuration. EC2 instances are charged per hour and pricing varies depending on the instance type and region. AWS also offers Auto Scaling to automatically adjust EC2 capacity based on demand.