0

I have written script to find instance-id from VPC n create AMI of each instance-id :

#!/bin/bash
#Script to Automate AMI backup

echo "----------------------------------\n   `date`   \n----------------------------------"

aws ec2 describe-instances --filters Name=vpc-id,Values=vpc-1c927479 |   awk '{ print $8 }' | sort -n   | grep  "i-" > /tmp/instanceid.txt


echo "Starting the Daily AMI creation: "

#To create AMI from instance-id 

for i in $(cat /tmp/instanceid.txt); do
        echo "Creating AMI for Instance id $i ......."

echo "instance-`date +%d%b%y`-$i" > /tmp/aminame.txt

aws ec2 create-image --instance-id $i --name "`cat /tmp/aminame.txt`" --description "This is created by ami-backup.sh" --no-reboot | grep -ir ami | awk '{print $4}' > /tmp/amiID.txt

echo  "AMI Name is: `cat /tmp/aminame.txt`\n"

echo done 

done

But i want to create to create AMIs excluding attached volumes for each volume !

ec2-create-image --block-device-mapping /dev/sdh=none

This will create ami without out attached volumes but /dev/sdh will be different for each instance so how do i automate this part ? any hint !

Ashish Karpe
  • 277
  • 2
  • 5
  • 19

1 Answers1

0

Command : $ aws ec2 describe-images --image-ids ami-xxxx |grep "/dev" | awk '{print $2}'

Output :

/dev/sda1

This is how we can find list of attached volumes and pass it to "ec2-create-image --block-device-mapping /dev/sdh=none"

Ashish Karpe
  • 277
  • 2
  • 5
  • 19