我编写了脚本来从 VPC 中查找 instance-id n 创建每个 instance-id 的 AMI:
#!/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
但我想创建 AMI,不包括每个卷的附加卷!
ec2-create-image --block-device-mapping /dev/sdh=none
这将在没有附加卷的情况下创建 ami,但 /dev/sdh 对于每个实例都会有所不同,那么我该如何自动化这部分呢?任何提示!
命令:$ aws ec2 describe-images --image-ids ami-xxxx |grep "/dev" | awk '{打印 $2}'
输出 :
/dev/sda1
这就是我们如何找到附加卷列表并将其传递给“ec2-create-image --block-device-mapping /dev/sdh=none”的方法