Short script to create and attach an EBS Volume in AWS

Short script for creating and attaching an EBS Volume to an EC2 instance. This is useful in cases where you want to dynamically create your EBS volumes outside of the cloud formation auto provisioning process.

 

Advertisements

2 Replies to “Short script to create and attach an EBS Volume in AWS”

  1. Hi this is not working when i am running from AWS instance to launch EBS instance and attach the same to instance..error i am getting is

    Creating Disk
    Device ID:
    Mount Point:
    KMS-ID:
    Size:
    Type:
    Tags:
    % Total % Received % Xferd Average Speed Time Time Time Current
    Dload Upload Total Spent Left Speed
    100 10 100 10 0 0 10917 0 –:–:– –:–:– –:–:– 10000
    % Total % Received % Xferd Average Speed Time Time Time Current
    Dload Upload Total Spent Left Speed
    100 19 100 19 0 0 23370 0 –:–:– –:–:– –:–:– 19000
    Tags: ResourceType=volume,Tags=[testing_ebs]
    Executing: aws ec2 create-volume –region eu-west-1 –availability-zone eu-west-1a –size 40 –volume-type gp2 –tag-specifications ResourceType=volume,Tags=[testing_ebs]
    ./ebs.sh: line 21: aws: command not found
    ./ebs.sh: line 22: jq: command not found
    Volume:ID
    Executing: aws ec2 wait volume-available –volume-ids
    ./ebs.sh: line 32: aws: command not found
    Executing: ec2 attach-volume –volume-id –instance-id i-0b10df31a59d7576d –device /dev/sdf
    ./ebs.sh: line 34: aws: command not found
    Executing: while [ ! -e /dev/sdf ]; do echo Waiting for EBS volume to attach; sleep 5; done
    Waiting for EBS volume to attach
    Waiting for EBS volume to attach
    Waiting for EBS volume to attach
    Waiting for EBS volume to attach
    Waiting for EBS volume to attach
    Waiting for EBS volume to attach
    Waiting for EBS volume to attach
    Waiting for EBS volume to attach
    Waiting for EBS volume to attach
    Waiting for EBS volume to attach
    Waiting for EBS volume to attach
    Waiting for EBS volume to attach

    Kindly let

    1. Your EC2 instance will need aws client tools, and the jq CLI utility, and an IAM role capable of executing these command

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.