Create EC2 Ami using bash script with No Reboot
Some we need to automate things based on our requirements, here is a simple script you can set as a cronjob to take your ec2 ami,Normally ec2 requires a reboot while taking ami’s/images. Here we can take ami without rebooting the ec2 instance using –no-reboot flag.
Create ec2 ami using bash script with no reboot
Step1. Create file /root/backup_ami.sh
Step2. You need access key & secret key , if you forgot your existing account’s access key & secret key,don’t worry, just create a IAM user with administrator privilege.
To create IAM user refer
https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users_create.html
Step3. Once you got secret key & access key,then put the below script.
#!/bin/bash export EC2_HOME="/opt/aws/apitools/ec2"; export JAVA_HOME="/usr/lib/jvm/jre"; /opt/aws/bin/ec2-create-image -O AKIAI%^^7557CF54KSFWEOEYPKQ -W tjCUvHnlQgcqYNYf/hfgdfss9t2tw62NJ7Tg7ywGkdxHgIr --region eu-central-1 -n box2.adminbirds.com-`date +%F` --no-reboot i-0c08624e96te3e029a
Here
change your keys AKIAI%^^7557CF54KSFWEOE tjCUvHnlQgcqYNYf/hfgdfss9t2tw62NJ7Tg7ywGkdxHgIr change your region eu-central-1 change your hostname box2.adminbirds.com change your instance id i-0c08624e96te3e029a save the file
chmod 755 /root/backup_ami.sh bash /root/backup_ami.sh
That’s all … done 🙂