Enable EBS snapshots by adding the following EC2 instance tag:
Now all EBS volumes that are attached to this EC2 instance will have snapshots created. (i.e. Three generations of rolling snapshots will be kept.)
- Download and install Node.js LTS
- Clone this repository
- Install dependencies:
cd ebs-fushu
npm ci
npm audit fix
Export AWS environment variables:
export AWS_ACCESS_KEY_ID='xx'
export AWS_SECRET_ACCESS_KEY='zz'
export AWS_REGION='us-east-1'
# Optionally enable debug messages
export DEBUG='ebs-fushu:*'
npm test
With dry run, no snapshots will be deleted and no snapshots will be created.
# Use _your_ AWS Owner ID
node app.js --owner-id=595959xxyybb --dry-run
As an example, if tag:snapshots
is set to 6
for an EC2 instance:
- The seventh oldest (and any older) snapshots will be deleted.
- A snapshot will be created for each attached volume.
In the following output, three EC2 instances (with one attached EBS volume each) are processed. For each EBS volume, one snapshot is deleted and a new one is created.
# Use _your_ AWS Owner ID
node app.js --owner-id=595959xxyybb
..
Deleting snapshot snap-0cde08cbbbbbbbbbb
Deleting snapshot snap-0ed981ccccccccccc
Deleting snapshot snap-0de499eeeeeeeeeee
Creating snapshot for volume vol-08d979defaaaaaaaa
Creating snapshot for volume vol-05dc1747dcccbbbbb
Creating snapshot for volume vol-017d181ae88888888
The IAM service account used with ebs-fushu will need the following permissions.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"ec2:Describe*",
"autoscaling:Describe*",
"ec2:CreateTags",
"elasticloadbalancing:Describe*",
"ec2:*Snapshot",
"cloudwatch:Describe*"
],
"Resource": "*"
}
]
}
Tested with:
Depending on your use case, the Amazon Data Lifecycle Manager for EBS Snapshots service may be an alternative to ebs-fushu
and similar custom-written apps.