Skip to main content

Stateful Elastic Block Storage (sebs)

Sebs was created for the situation where you need to stick a stateful application in an AutoScaling group with a max size of 1. Sebs will make sure that if the instance is recreated that the previous volume is reattached back to the instance regardless of which AZ the instance is recreated in.

Why

A single instance ASG is good protection in the event that the instance is retired. It can also help enable rolling upgrades and DR in the event that the AZ your instance is in goes down.

Prerequisites

  • python3
  • EC2 Instance Profile with access to create/delete snapshots and volumes.

Example IAM Policy

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "ec2:DetachVolume",
                "ec2:AttachVolume",
                "ec2:DeleteVolume",
                "ec2:DeleteSnapshot",
                "ec2:CreateTags",
                "ec2:CreateSnapshot",
                "ec2:CreateVolume"
            ],
            "Resource": [
                "arn:aws:ec2:*:*:instance/*",
                "arn:aws:ec2:*::snapshot/*",
                "arn:aws:ec2:*:*:volume/*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "ec2:DescribeInstances",
                "ec2:DescribeVolumes",
                "ec2:DescribeSnapshots"
            ],
            "Resource": "*"
        }
    ]
}

Installing

Sebs should be run from an EC2 instance and can be run from userdata or any CaC tool. Sebs can be installed from pip or GitHub.

From pip

pip install sebs

From GitHub

python3 -m pip install git+https://github.com/DontShaveTheYak/sebs.git#egg=sebs

Usage

sebs
usage: sebs [-h] -b BACKUP [-n NAME] [-v] [--version]

optional arguments:
  -h, --help            show this help message and exit
  -b BACKUP, --backup BACKUP
                        <Required> List of Devices to Backup
  -n NAME, --name NAME  <Optional> specify a your app name.
  -v, --verbose         Verbosity (-v, -vv, etc)
  --version             show program's version number and exit

Note: If you are going to have more than one instance in a single region use sebs, then you need to pass in a name.

sebs -b /dev/xvdz -n ${MY_APP_NAME}

Here is an example userdata script

#!/bin/bash
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1

echo "Running Sebs"
yum install python3 -y
python3 -m pip install sebs

# On RHEL and Amazon Linux2 /usr/local/bin is not in the path for root user.
/usr/local/bin/sebs -b /dev/xvdz -n example-app

echo 'Waiting on device /dev/xvdz to be available.'
while [ ! -e /dev/xvdz ] ; do sleep 1 ; done
echo 'Device is ready.'

On first run sebs will mark the volume mounted at /dev/xvdz with a control tag. If the instance is re-created sebs will look for a volume with the control tag and if found it will then mount that volume to the instance as the same device as before.

Contributing

Please read CONTRIBUTING.md.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

To see what has changed see the CHANGELOG.

License

This project is licensed under the GPLv3 License - see the LICENSE file for details

Metadata

Release files for sebs 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sebs 0.5.1
File Size Uploaded
sebs-0.5.1.tar.gz 14.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sebs 0.5.1
File Interpreter ABI Platform
sebs-0.5.1-py3-none-any.whl Python 3 none any Details

Total release size: 43.9 kB

Release files / sebs-0.5.1.tar.gz

Download URL sebs-0.5.1.tar.gz
Size 14.8 kB
Tags Source
SHA-256 checksum
How to use checksums
441188b80298c3e68639f397aae25b894ef60ba60db751c61724a285cabcff18
BLAKE2b-256 checksum
How to use checksums
ff60c887e4fca740c1a11d537f96fb0a1419c09ce99f63b02e2a356028604a3f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

Release files / sebs-0.5.1-py3-none-any.whl

Download URL sebs-0.5.1-py3-none-any.whl
Size 29.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a2ecafd71d66ade660061c5a0ee2d87a44ca31de5584f75ce0ce0d50e7f97653
BLAKE2b-256 checksum
How to use checksums
8e185c4308a4d34248e2130f2223b4009719c0a7c40075a3c2efd964449756da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

Release history Release notifications | RSS feed

This release

0.5.1 This release

2 release files

0.5.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page