Skip to main content

Create Stateful Elastic Block Storage on AWS.

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sebs-0.5.1.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

sebs-0.5.1-py3-none-any.whl (29.1 kB view details)

Uploaded Python 3

File details

Details for the file sebs-0.5.1.tar.gz.

File metadata

  • Download URL: sebs-0.5.1.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for sebs-0.5.1.tar.gz
Algorithm Hash digest
SHA256 441188b80298c3e68639f397aae25b894ef60ba60db751c61724a285cabcff18
MD5 0674a0e1495d7b88ec4e7f2f5c30a6c6
BLAKE2b-256 ff60c887e4fca740c1a11d537f96fb0a1419c09ce99f63b02e2a356028604a3f

See more details on using hashes here.

File details

Details for the file sebs-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: sebs-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 29.1 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for sebs-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a2ecafd71d66ade660061c5a0ee2d87a44ca31de5584f75ce0ce0d50e7f97653
MD5 90bf268b2709ebd476416f8470bf9b1d
BLAKE2b-256 8e185c4308a4d34248e2130f2223b4009719c0a7c40075a3c2efd964449756da

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page