Bash script for Automatic EBS Snapshots and Cleanup on Amazon Web Services (AWS). Created by CaseyLabs.
Switch branches/tags
Nothing to show
Clone or download
CaseyLabs Merge pull request #25 from bryant1410/master
Fix broken headings in Markdown files
Latest commit a71a28a Jun 19, 2017
Failed to load latest commit information.
LICENSE Create LICENSE Jul 11, 2014 Fix broken Markdown headings Apr 17, 2017 Script comment cleanup Aug 11, 2015


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

Written by [AWS Consultants - Casey Labs Inc.] (

Contact us for all your Amazon Web Services consulting needs!


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

Pull requests greatly welcomed!



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

    "Version": "2012-10-17",
    "Statement": [
            "Sid": "Stmt1426256275000",
            "Effect": "Allow",
            "Action": [
            "Resource": [

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

First, make sure Python pip is installed:

# Ubuntu
sudo apt-get install python-pip -y

# Red Hat/CentOS
sudo yum install python-pip -y

Then install the AWS CLI tools:

sudo pip install awscli

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

sudo aws configure

AWS Access Key ID: (Enter in the IAM credentials generated above.)
AWS Secret Access Key: (Enter in the IAM credentials generated above.)
Default region name: (The region that this instance is in: i.e. us-east-1, eu-west-1, etc.)
Default output format: (Enter "text".)```

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

cd ~
chmod +x
mkdir -p /opt/aws
sudo mv /opt/aws/

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

55 22 * * * root  AWS_CONFIG_FILE="/root/.aws/config" /opt/aws/

# Or written another way:
55 22 * * * root  /opt/aws/

To manually test the script:

sudo /opt/aws/