Here is small useful script which will help you to attach volume on ec2 instances without login into the AWS console.

I’m connected to AWS using VPN, so following script will work with private ip but if you are not connected to vpn, then you can change PrivateIpAddress to PublicIp

#!/bin/bash

set -e

# Create and Attach Volume to Instace using IP Address

export AWS_ACCESS_KEY_ID=XXX
export AWS_SECRET_ACCESS_KEY=XXXXXX
export REGION=us-east-1
export AWS_DEFAULT_REGION=$REGION

if [[ $# -ne 2 ]]
then
    echo "Usage: $0 <hostname|IP> <size>"
    exit 1
fi

msg(){

    echo "=========={$@}=========="

}

get_instance_data(){
    # returns ZONE STATUS IP INSTANCE_ID DEVICE
    local host=$1
    if ! echo $host | grep -qE '\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4}\b'
    then
         host=$(dig +short $host)
    fi
    raw_data="$(aws ec2 describe-instances \
        --query 'Reservations[*].Instances[*].[Placement.AvailabilityZone, State.Name,PrivateIpAddress,InstanceId,BlockDeviceMappings[*].DeviceName]' \
        --output text | grep -A1 "${host}\t")"
    instance_data="$( echo "${raw_data}" | head -1 )"
    vid=$( echo "${raw_data}" | grep -o 'sd.' | sort | uniq | tail -1 | cut -c 3- | tr "0-9a-z" "1-9a-z_")
    echo "${instance_data}" "/dev/sd${vid}"
}

msg "Fetching Instance Data"
read ZONE STATUS IP INSTANCE_ID DEVICE <<<"$(get_instance_data $1)"
msg "Done"

msg "Creating Volume in Zone $ZONE for IP $IP [ID: $INSTANCE_ID]"
volume_id="$(aws ec2 create-volume --size ${2:-10} --region $REGION --availability-zone $ZONE --volume-type standard | jq -r .VolumeId)"

msg "Volume has been created with ID:$volume_id"
echo "Waiting for Volume availability" && sleep 30
msg "Attaching to Instance"
aws ec2 attach-volume --volume-id $volume_id  --instance-id $INSTANCE_ID --device $DEVICE

Output

=========={Fetching Instance Data}==========
=========={Done}==========
=========={Creating Volume in Zone us-east-1b for IP 172.31.19.121 [ID: i-07208ea25a760e769]}==========
=========={Volume has been created with ID:vol-04b537f936fe0c0e9}==========
Waiting for Volume availability
=========={Attaching to Instance}==========
{
    "AttachTime": "2017-05-03T07:55:00.921Z",
    "InstanceId": "i-07208ea25a760e769",
    "VolumeId": "vol-04b537f936fe0c0e9",
    "State": "attaching",
    "Device": "/dev/sdd"
}