Skip to content

TechDirectArchive

Hands-on IT, Cloud, Security & DevOps Insights

  • Home
  • About
  • Advertise With US
  • Contact
  • Reviews
  • Toggle search form
Home » AWS/Azure/OpenShift » Add an EBS volume to AWS EC2 via the AWS Console and CLI
  • portainer feature
    How to Install Docker Portainer on Linux Containers
  • cockpit
    Installation and configuration of Cockpit on CentOS Linux Linux
  • ffd
    Unable to bind to LDAP or AD in Pleasant Password Server Password Manager
  • How to Disable the Command Prompt on Windows 11
    How to Disable the Command Prompt on Windows 11 Windows
  • maxresdefault
    How to join a computer to the Domain Windows Server
  • images 2
    How to configure and use Pleasant Password RDP SSO Password Manager
  • Data drive is locked by BitLocker and not OS drive Fastboot Option
    Fast Boot Options: Fix specific Drive issue with BitLocker [MBAM] Windows
  • Screenshot 2020 07 25 at 13.09.08
    Fix the following error occurred when DNS was queried for the service location Windows Server

Add an EBS volume to AWS EC2 via the AWS Console and CLI

Posted on 22/04/202227/03/2024 Dickson Victor By Dickson Victor No Comments on Add an EBS volume to AWS EC2 via the AWS Console and CLI
EBS-EC2

Amazon’s Elastic Block Store (EBS) is a block-storage service provided by the Amazon Elastic Compute Cloud (EC2) to store the data which can be kept on the EBS servers even if the EC2 instances are shut down or not working. In this article, we will see how you can add an EBS volume to AWS EC2, using AWS CLI Commands. Please see How to create an EC2 Instance, Various ways to restart an AWS EC2 instance, and “AWS CLI Error: All commands return Unknown output type [None]“.

An EBS data volume can be attached, or detached dynamically, irrespective of the EC2 to which the volume is attached. EBS is an easy-to-use service that provides high scalability, availability (99.999%), and protection against failures.

Kindly refer to some of these related guides: AWS ec2 and multi-cloud, and how to Deploy MVC Application to AWS EC2 Using RDP. In this article, you will learn how to Add an EBS volume to AWS EC2 via the AWS Console and CLI.

There are 2 ways for adding an EBS volume to an EC2 instance.

  1. Creating and attaching an EBS while creating an EC2 instance.
  2. Adding EBS volume to an already created EC2 instance.

Let us first install the AWS CLI. Remember to install the AWS CLI according to your operating system.

Installing AWS CLI in Linux

Open the command prompt, and execute the following command. Here is a guide on how to configure AWS CLI, and

curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "aws-ec2-ebs.zip"

Unzip the package that has just been downloaded in the above step.

unzip aws-ec2-ebs.zip

Run the installation of the package using the command.

sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws

After installing the AWS CLI, configure it so that it will be able to connect to the AWS account. To configure the AWS CLI use the following command

aws configure

It will ask for the AWS credentials, Access Key ID, and Secret Access Key after entering your credentials. It will get connected to the AWS account. Once the CLI is configured, follow the steps below to either create an EC2 instance and then attach an EBS Volume to it.

Here are some exciting articles: How to Deploy Dynamic Website to AWS EC2, How to host Static Website and Versioning on AWS S3, and how to deploy an Angular App to AWS S3.

Creating an EC2 instance in order add the EBS Volume

Create a key pair by writing the following command in the AWS CLI,

aws ec2 create-key-pair --key-name TempKey

Here “TempKey” is the key name you want to give to your key. This key pair will be used to create an EC2 instance.

In the console, create the security group by typing the following command.

aws ec2 create-security-group --group-name ec2-aws-allowall --description “Allow all traffic for ec2”
image-27

The security group is the instance-level firewall security provided by the AWS to control the incoming and outgoing traffic for the instance.

Copy this security group id from the Type the following command for launching an Amazon Linux AMI2 instance with the key pair and security group that has been created before. 

Remember to replace AMI ID, subnet ID, and the security group ID in the command.

aws ec2 run-instances --image-id <REPLACE_AMI_ID_HERE> --instance-type t2.micro --count 1 --subnet-id <REPLACE_SUBNET_ID_HERE> --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=aws-ec2-instance}]' --security-group-ids <REPLACE_SECURITY_GROUP_ID_HERE> --key-name TempKey

You should see an output similar to the following. Please copy and save the instance id.

image-28

Creating an EBS volume

Let us now use a command to create an EBS volume of 30 GB. Use the same subnet name (for example us-east-1a or eu-west-1b) of which you have supplied the id in the above command.

aws ec2 create-volume --availability-zone <REPLACE_WITH_THE_SUBNET_NAME> --size 30 

You Should see an output similar to the following. Please copy the volume ID here.

image-29

Add an EBS volume to AWS EC2 via the AWS

To attach the EBS to the EC2 instance, Add the EBS created to the instance that has been created before with the following command.

aws ec2 attach-volume --instance-id <REPLACE_WITH_INSTANCE_ID> --volume-id <REPLACE_WITH_THE_VOLUME_ID> --device /dev/xvdh
image-30

You can write your preferred device name instead of /dev/xvdh. After executing the above command, an EBS volume will be added to the EC2 instance that we have created. Thus keeping the data protected, available, and persistent.

You can also do this step on the AWS Console. Find the volume created using the volume Id. It should be in the ‘Available State’. Select the volume, click on the action button and Choose the Attach Volume option.

image-32

Choose the EC2 instance from the list, type in the device name, and click the Attach Volume button.

image-31

We have now successfully created an EC2 instance and attached an EBS volume to it. I hope this article helps you add an EBS volume to AWS EC2 via the AWS Console and CLI. Let me know if you have any questions.

Rate this post

Thank you for reading this post. Kindly share it with others.

  • Click to share on X (Opens in new window) X
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to share on Tumblr (Opens in new window) Tumblr
  • Click to share on Telegram (Opens in new window) Telegram
  • Click to share on WhatsApp (Opens in new window) WhatsApp
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on Bluesky (Opens in new window) Bluesky
  • Click to share on Threads (Opens in new window) Threads
  • Click to share on Nextdoor (Opens in new window) Nextdoor
AWS/Azure/OpenShift Tags:AWS, AWS CLI, EC2, EC2 instance

Post navigation

Previous Post: Fix we could not find a camera compatible with Windows Hello Face
Next Post: Hide YouTube Subscriber Count: Privacy for Channel Subscriptions

Related Posts

  • Set a Resource Delete Lock
    How to Add a Delete Lock on Azure Resources AWS/Azure/OpenShift
  • feature functionapp
    Deploy a function app from Visual Studio to Azure Platform AWS/Azure/OpenShift
  • header picture 1
    Azure CI/CD: Configuring Email Notifications in Azure DevOps AWS/Azure/OpenShift
  • Screenshot 2024 02 09 at 7.34.18 PM
    How to create a Logic App for monitoring tweets AWS/Azure/OpenShift
  • AZMFeature
    Performance and Diagnostics in Microsoft Cloud with Azure Monitor AWS/Azure/OpenShift
  • azure logo 1
    How to use the built-in Azure Active Directory Connect tool AWS/Azure/OpenShift

More Related Articles

Set a Resource Delete Lock How to Add a Delete Lock on Azure Resources AWS/Azure/OpenShift
feature functionapp Deploy a function app from Visual Studio to Azure Platform AWS/Azure/OpenShift
header picture 1 Azure CI/CD: Configuring Email Notifications in Azure DevOps AWS/Azure/OpenShift
Screenshot 2024 02 09 at 7.34.18 PM How to create a Logic App for monitoring tweets AWS/Azure/OpenShift
AZMFeature Performance and Diagnostics in Microsoft Cloud with Azure Monitor AWS/Azure/OpenShift
azure logo 1 How to use the built-in Azure Active Directory Connect tool AWS/Azure/OpenShift

Leave a Reply Cancel reply

You must be logged in to post a comment.

Microsoft MVP

VEEAMLEGEND

vexpert-badge-stars-5

Virtual Background

GoogleNews

Categories

veeaam100

sysadmin top30a

  • portainer feature
    How to Install Docker Portainer on Linux Containers
  • cockpit
    Installation and configuration of Cockpit on CentOS Linux Linux
  • ffd
    Unable to bind to LDAP or AD in Pleasant Password Server Password Manager
  • How to Disable the Command Prompt on Windows 11
    How to Disable the Command Prompt on Windows 11 Windows
  • maxresdefault
    How to join a computer to the Domain Windows Server
  • images 2
    How to configure and use Pleasant Password RDP SSO Password Manager
  • Data drive is locked by BitLocker and not OS drive Fastboot Option
    Fast Boot Options: Fix specific Drive issue with BitLocker [MBAM] Windows
  • Screenshot 2020 07 25 at 13.09.08
    Fix the following error occurred when DNS was queried for the service location Windows Server

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,839 other subscribers
  • RSS - Posts
  • RSS - Comments
  • About
  • Authors
  • Write for us
  • Advertise with us
  • General Terms and Conditions
  • Privacy policy
  • Feedly
  • Telegram
  • Youtube
  • Facebook
  • Instagram
  • LinkedIn
  • Tumblr
  • Pinterest
  • Twitter
  • mastodon

Tags

AWS Azure Bitlocker Microsoft Windows PowerShell WDS Windows 10 Windows 11 Windows Deployment Services Windows Server 2016

Copyright © 2025 TechDirectArchive

 

Loading Comments...
 

You must be logged in to post a comment.