Guide to Creating an AWS EC2 Instance
Amazon EC2 (Elastic Compute Cloud) is an AWS web service that allows users to rent virtual servers known as instances in the cloud. By creating an AWS EC2 instance you can run applications, host websites, and perform various computing tasks without the need to invest in and maintain physical hardware.
One of the great features of Amazon EC2 instances is the pay-as-you-go model. With on-demand instances, you only pay for the computing capacity you use, which is billed by the hour. This flexibility makes Amazon EC2 instances cost-effective, as you can scale resources up or down as needed.
In this article, we will look at how to create and manage Amazon EC2 instances.
Accessing the AWS EC2 Service
To start working with Amazon EC2 instances you will need to log into your AWS account.
- Open your web browser and log into the AWS Management Console with your account
- At the top of the page use the search bar to search for EC2
- Select the EC2 service
Creating an EC2 Instance
- Once you are in the Amazon EC2 Service you can create a new instance
- Select the region that the Amazon EC2 Instance will be created in by selecting the dropdown on the top right of the screen.
- Next, click on the Launch Instance Button to get started
- This will take you to the Launch an Instance wizard
- Give the Instance a name (e.g. My-Ubuntu-Server-01)
- The next step is to select an AMI (Amazon Machine Image) that will be used to launch your image.
An AMI is a pre-configured template used to launch virtual servers on Amazon EC2 with the necessary OS, software, configurations, and data. - To learn more about Amazon Machine Images visit the AWS documentation by following the link below
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html - For this example we will select the Ubuntu image which is free tier eligible.
- The next step is to select the Instance type.
An Instance type is a predefined virtual hardware configuration for a EC2 instance, specifying its CPU, memory, storage, and network capacity, tailored to different performance and cost requirements. - To learn more about the different types of Instance types visit the AWS documentation by following the link below
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html
- Next you will need to create a key pair or select an existing one
A key pair is a set of security credentials used to connect to an Amazon EC2 Instance. It consists of a public key, which you can share openly, and a secret private key that you must keep safe.
- If creating a new key pair click on the Create new key pair link and fill in the details as below selecting the appropriate format
- Remember to store the private key in a secure place.
- For more information on creating key pairs visit the following AWS guide
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/create-key-pairs.html
- Next configure your network settings by selecting your VPC and Subnet. This can be defined by clicking on the Edit button if needed.
- Then select or create security groups to control inbound and outbound access to the instance.
- Configure storage by setting the root volume and add any other volumes required.
- Change any settings required in advanced Settings link
- Then review the summary and click on the launch instance button to create the instance.
- It can take 10 mins to create your instance. When complete you will receive the success notification as shown below.
- Once complete you can view and manage your instance from the Instances menu.
Managing an AWS EC2 Instance
Once an instance is created it can be managed from the Instances portal
To manage an instance or group of instances, select the instances then click on the Instance state dropdown menu.
From here you can select one of the following options:
- Stop Instance
- This allows you to temporarily shut down an EC2 instance without terminating it.
- When you stop an instance, its state is preserved and all data on the instance storage volumes remain intact. The instance can be easily started again at a later time.
- Stopping an instance will release the instance IP address but keeps the root volume and any attached EBS storage volumes.
- Stopping an instance can help reduce costs for workloads that only need to run intermittently.
- Start Instance
- This allows you to restart an EC2 instance that was previously stopped.
- When you start a stopped instance, a new instance boot volume is created from the preserved root volume and any attached EBS volumes are reattached. The instance will be provisioned with the same configuration it had when it was stopped.
- Starting an instance will assign a new public IP address unless an Elastic IP is attached.
- Reboot Instance
- The reboot instance option allows you to restart an EC2 instance without terminating it.
- Rebooting an instance is similar to restarting a computer server. The instance will shut down and restart on the same physical host it was running on previously.
- A reboot will maintain the public and private IP addresses of the instance.
- Rebooting is useful for applying updates or changes to the instance configuration. For example, if you update security groups or instance metadata, a reboot will allow those changes to take effect.
- The reboot process typically takes 1-2 minutes to fully restart the instance.
- Hibernate Instance
- The hibernate instance option allows you to preserve the in-memory state of an EC2 instance when you stop it.
- When an instance is hibernated, the OS is stopped and the contents of RAM are written to your EBS root volume. When you restart the hibernated instance, the OS boots up much faster because it doesn’t need to fully reboot and reload data into memory. The instance is resumed on the same host using the preserved RAM state.
- Hibernation can provide faster start up times compared to stopping and starting an instance.
- The hibernated state is preserved until you restart or terminate the instance.
- Hibernation is only available for instances with an EBS root volume backed by certain instance types.
- Terminate Instance
- The terminate instance option permanently deletes an EC2 instance along with any data on its attached instance storage volumes.
- When an instance is terminated, the instance shuts down and its status changes to ‘terminated’. The underlying host computer resources are released back into EC2 capacity pools to be used for other instances. Any EBS volumes attached to the instance by default will be preserved after termination.
- Terminating an instance immediately frees you from accruing usage costs for that instance. However, you cannot reconnect to a terminated instance or restore it to its previous state. You would need to launch a new instance instead.
- Use caution before terminating an instance to avoid unintended data loss.
Further Reading
For more information visit the AWS documentation by following the link below
https://docs.aws.amazon.com/ec2/
Newsletter
Join our newsletter