Amazon (AWS) Ec2 automatic SnapShot

Bash script for Automatic EBS Snapshots and Cleanup on Amazon Web Services (AWS)

How it works: will:

  • Determine the instance ID of the EC2 server on which the script runs
  • Gather a list of all volume IDs attached to that instance
  • Take a snapshot of each attached volume
  • The script will then delete all associated snapshots taken by the script that are older than 7 days


IAM User: This script requires that new IAM user credentials be created, with the following IAM security policy attached:

AWS CLI: This script requires the AWS CLI tools to be installed.

First, make sure Python pip is installed:

Then install the AWS CLI tools:

Once the AWS CLI has been installed, you’ll need to configure it with the credentials of the IAM user created above:

Install Script: Download the latest version of the snapshot script and make it executable:

Then put the code in


You should then setup a cron job in order to schedule a nightly backup. Example crontab jobs:

To manually test the script:

This entry was posted in CentOS, Debian, Hosting, Linux Post, RHEL, Scripting, Ubuntu. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">