semvec/pypi-packages huggingface dataset:
chesney 1.0
A Python package to indicate if this EC2 instance should be the one and only to perform a task within an auto-scaling group.
License: MIT

# py-chesney

[![CircleCI](https://circleci.com/gh/cariad/py-chesney/tree/master.svg?style=svg)](https://circleci.com/gh/cariad/py-chesney/tree/master)

A Python package to indicate if an AWS EC2 instance is *the one and only* appointed to perform a special task within an auto-scaling group.

## Motivation

Let's say you've got a fleet of EC2 instances, deployed via an auto-scaling group, all serving web content from a shared network drive.

Now, let's say you want to appoint one of those EC2 instances to be *the one and only* to backup the shared content to another location.

If the launch configuration set up *every* instance to perform the backup then they could all end up tramping over each other, and there'd be a ton of wasted traffic. If you manually configured one as a special case to perform the backup, then what happens when that instance goes down?

(Of course, you might decide to have a *totally separate* EC2 instance connect to the network drive to perform the backup, so that your web servers don't hold multiple responsibilities. This would be a good idea. I'm assuming that your project ain't worth that level of infrastructure, and you're happy with instances holding multiple responsibilities.)

`chesney` solves this problem by ensuring it returns `true` for only *one* EC2 instance within an auto-scaling group, and `false` for all the rest. This means you can configure all of your instances to -- for example -- perform a daily check to see if they're *the one and only*, and then initiate the backup only if they are.

## Installation

```shell
pip install chesney
```

## Command-line usage

```shell
python -m chesney [--log-level LEVEL]
```

Will return either `true` or `false`.

## Code usage

```python
import chesney

if chesney.is_appointed():
    # Do the thing
else:
    # Don't do the thing.
```

## Permissions

You must run `chesney` with the following permissions:

- `autoscaling:DescribeAutoScalingGroups`
- `ec2:DescribeInstances`

An IAM policy would look something like this:

```yaml
PolicyName: AllowChesney
PolicyDocument:
  Statement:
    - Effect: Allow
      Action:
        - "autoscaling:DescribeAutoScalingGroups"
        - "ec2:DescribeInstances"
      Resource:
        - "*"
```

## Development

### Prerequisites

`chesney` requires Python 3.x.

### Installing dependencies

```shell
pip install -e .[dev]
```

### Running tests

```shell
python test.py
```

## Changelog

### v1.0 - 2018-12-03

- Initial release.