Skip to main content

aws-tools

PyPI

This package provides tools for AWS platform, such as:

  • switching between multiple accounts

  • renewing API access keys

and others.

The main reason why aws-tools came to be, was using awscli with different access keys in the secure and easy way.

How it works

Switching between AWS accounts:

$ awsenv test
<test> $ aws s3 ls
...list of S3 objects on TEST environment...

### Explanation:
### <test> $ env | grep AWS
### AWS_SECRET_ACCESS_KEY=w0bM0rucARITPOUpcyAaX3iI9lGjJo7g8UUCUxIv
### AWS_ACCESS_KEY_ID=AKIAJPVK7VGH6CBZT5EQ
### AWS_ENV=test

<test> $ awsenv prod
<prod> $ aws s3 ls
...list of S3 objects on PROD environment...

### Explanation:
### <prod> $ env | grep AWS
### AWS_SECRET_ACCESS_KEY=P8crbSIvQ/Au0jfnW8XER9eJKxpQdYqpRVz5QxKo
### AWS_ACCESS_KEY_ID=AKIAJ4F26CMBPI1HF7MQ
### AWS_ENV=prod

Renewing AWS API access keys:

$ awsenv prod

### Explanation:
### <prod> $ env | grep AWS
### AWS_SECRET_ACCESS_KEY=P8crbSIvQ/Au0jfnW8XER9eJKxpQdYqpRVz5QxKo
### AWS_ACCESS_KEY_ID=AKIAJ4F26CMBPI1HF7MQ
### AWS_ENV=prod

<prod> $ awsroll prod
Rolled key for env prod: AccessKeyId=****************ZKQFQ; CreateDate=2018-11-14 13:10:04+00:00
<prod> $ awsenv prod

### Explanation:
### <prod> $ env | grep AWS
### AWS_SECRET_ACCESS_KEY=napb9J2RKzsSiTIjLRavN09qIfFzrMo7846zr2ou
### AWS_ACCESS_KEY_ID=AKIAJTGB6EFV7F4ZKQFQ
### AWS_ENV=prod

Getting started

Prerequisites:

aws-tools requires gpg (version >= 2.X) to decrypt/encrypt your AWS credentials.

Install necessary packages, and generate a new key pair:

$ sudo apt-get install gpg gpg-agent
$ gpg --gen-key

This document covers only gpg commands required to run aws-tools! If you need to use other gpg parameters, go to gpg documentation.

Configure your region using awscli if you haven’t done that yet:

$ aws configure
AWS Access Key ID [None]:
AWS Secret Access Key [None]:
Default region name [None]: eu-west-1
Default output format [None]:

Do not provide any keys here!

Installation

Simply run:

$ pip install --user aws-tools

Configuration

AWS Credentials

In ~/.aws directory create temporary env.<environment>.conf file for each AWS environment.

For example, if you have 3 AWS environments: TEST, STAGE and PROD, there should be 3 config files in ~/.aws directory:

env.test.conf
env.stage.conf
env.prod.conf

Edit each file:

[default]
aws_access_key_id = <your_environment_specific_access_key_id>
aws_secret_access_key = <your_environment_specific_secret_access_key>

Encrypt each file with gpg:

$ gpg --encrypt --armor --output env.<environment>.conf.asc -r <your-gpg-user-id-name> env.<environment>.conf

and remove temporary env.*.conf files!

Run gpg -K to find out what is your <your-gpg-user-id-name>

Shell

aws-tools comes with handy command completion and bash prompt features. Simply add to your ~/.bashrc:

source $HOME/.local/bin/aws_tools_completion.bash 2>/dev/null
export PS1="\$(__awsenv_ps1 2>/dev/null)${PS1}"

SMTP credentials (optional)

This step is helpful if you want to send renewed AWS access keys to an email.

In ~/.aws directory create temporary smtp.cfg file.

Edit smtp settings:

smtplogin = <your_full_smtp_login>
smtppass = <your_password>
smtphost = <smtp_host>
smtpport = <smtp_port>

Encrypt config file with gpg:

$ gpg --encrypt --armor --output smtp.cfg.asc -r <your-gpg-user-id-name> smtp.cfg

and remove temporary smtp.cfg file!

Usage

Examples

Autocompletion:

$ awsenv<TAB><TAB>
prod stage test

Use TEST access keys:

$ awsenv test

Unset AWS access keys for current shell:

$ awsenv unset

Rotate PROD access keys:

$ awsroll prod

Rotate access keys for all environments:

$ awsroll

Rotate access keys for all environments using gpg agent, and send them to the email:

$ aws-roll-keys.py -a -e all -s <email@domain.org>

Rotate access keys for TEST environment and send info to the email:

$ aws-roll-keys.py -e test -i <email@domain.org>

Release files for aws-tools 1.1.9

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

Source distribution (sdist)

Source distribution for aws-tools 1.1.9
File Size Uploaded
aws-tools-1.1.9.tar.gz 10.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aws-tools 1.1.9
File Interpreter ABI Platform
aws_tools-1.1.9-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 22.0 kB

Release files / aws-tools-1.1.9.tar.gz

Download URL aws-tools-1.1.9.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
5508152dfd3ed7fa3de081ac41c8123e08f68bd9ebc97ce241c1c38721f2a04b
BLAKE2b-256 checksum
How to use checksums
5808f9bc9ef2c2b138e1a45be0acecd05db932138ffed38e0ce912270d8d531b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.7.1

Release files / aws_tools-1.1.9-py2.py3-none-any.whl

Download URL aws_tools-1.1.9-py2.py3-none-any.whl
Size 11.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
aa4d485bbfa1201f790753194f12b9ff9420f75f3f8054837bb56483c6f91966
BLAKE2b-256 checksum
How to use checksums
9eb7df22290cddb374c644de7158c2618666c73a06c299df403697bb327352a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.7.1

Release history Release notifications | RSS feed

This release

1.1.9 This release

2 release files

1.1.8

2 release files

1.1.7

2 release files

1.1.6

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.27

2 release files

1.0.18

2 release files

1.0.17

1.0.16

1.0.15

2 release files

1.0.14

1 release file

1.0.13

1 release file

1.0.11

1 release file

1.0.9

1 release file

1.0.8

1 release file

1.0.7

1 release file

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