Skip to content

TechDirectArchive

Hands-on IT, Cloud, Security & DevOps Insights

  • Home
  • About
  • Advertise With US
  • Reviews
  • Contact
  • Toggle search form
Home » AWS/Azure/OpenShift » Add an EBS volume to AWS EC2 via the AWS Console and CLI

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.

  • Share on X (Opens in new window) X
  • Share on Reddit (Opens in new window) Reddit
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Facebook (Opens in new window) Facebook
  • Share on Pinterest (Opens in new window) Pinterest
  • Share on Tumblr (Opens in new window) Tumblr
  • Share on Telegram (Opens in new window) Telegram
  • Share on WhatsApp (Opens in new window) WhatsApp
  • Share on Mastodon (Opens in new window) Mastodon
  • Share on Bluesky (Opens in new window) Bluesky
  • Share on Threads (Opens in new window) Threads
  • 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

  • AZURE Kubernetes Service Upgrade
    AZURE Kubernetes Service (AKS) upgrade minor version from 1.32.3 to 1.33.7 AWS/Azure/OpenShift
  • Webp.net resizeimage 4
    Create a Service Fabric Cluster using the Azure Stack Hub portal and the CLI AWS/Azure/OpenShift
  • S3 Bucket
    Access AWS Management Console and Create Resources with AWS CLI on Windows AWS/Azure/OpenShift
  • azure logo
    Azure CLI commands: How to use Azure Command-line Interface AWS/Azure/OpenShift
  • azure resource groups 1
    Setup Public Load Balancer in Azure AWS/Azure/OpenShift
  • Amazon
    Import Virtual Machines to AWS as AMI AWS/Azure/OpenShift

More Related Articles

AZURE Kubernetes Service Upgrade AZURE Kubernetes Service (AKS) upgrade minor version from 1.32.3 to 1.33.7 AWS/Azure/OpenShift
Webp.net resizeimage 4 Create a Service Fabric Cluster using the Azure Stack Hub portal and the CLI AWS/Azure/OpenShift
S3 Bucket Access AWS Management Console and Create Resources with AWS CLI on Windows AWS/Azure/OpenShift
azure logo Azure CLI commands: How to use Azure Command-line Interface AWS/Azure/OpenShift
azure resource groups 1 Setup Public Load Balancer in Azure AWS/Azure/OpenShift
Amazon Import Virtual Machines to AWS as AMI 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

Veeam Vanguard

  • configure kerberos
    Configure Kerberos Delegation in Windows Windows
  • azure active director
    AD Connect Error: The Synchronisation service scheduler is currently synchronization and the configuration change cannot be made at this time AWS/Azure/OpenShift
  • convert HEIC image format to JPEG format
    Convert HEIC images to JPEG format on Mac with Quick Actions Mac
  • How to Fix MS SQL Error 832
    MSSQL Server Error 833: Synthesis of Real-World Case Studies Oracle/MSSQL/MySQL
  • image 75
    Useful Tutorial on CBackup Software Network | Monitoring
  • veeam backup for Proxmox VE
    Backup and Restore Proxmox VE virtual machines with Veeam Backup
  • RDlicensePerUser
    RDS client access licenses: How to install a new Per User Remote Desktop Services license Windows Server
  • 1 WeXxkEX0JG3oB781HD8Hrg 1
    OOBESETTINGSMULTIPLEPAGE error on Windows 10 Windows

Subscribe to Blog via Email

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

Join 1,808 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.