Skip to main content

aws-assume

https://travis-ci.org/zulhilmizainuddin/aws-assume.svg?branch=master Maintainability

Execute AWS CLI commands after assuming role

Prerequisite

  • Python 3.6 or above

  • AWS CLI or equivalent AWS supported CLI

Install

Install using pip

$ pip install awsassume

Install using setup script

$ python setup.py install

Usage

usage: awsassume [-h] -a ROLE_ARN -n ROLE_SESSION_NAME [--no-cache]
                 [-r REGION] [-c COMMAND [COMMAND ...]]

Execute AWS CLI commands after assuming role

optional arguments:
  -h, --help            show this help message and exit
  --no-cache            Disable caching of the assumed role response
  -r REGION, --region REGION
                        The region to be associated with the client
  -c COMMAND [COMMAND ...], --command COMMAND [COMMAND ...]
                        The AWS CLI command to execute after assuming role

required arguments:
  -a ROLE_ARN, --role-arn ROLE_ARN
                        The ARN of the role to assume
  -n ROLE_SESSION_NAME, --role-session-name ROLE_SESSION_NAME
                        An identifier for the assumed role session

Caching

By default, the assumed role response will be cached to ~/.awsassume/cache and used until it expires. The cache will expire one hour after the assume role request is successful.

If caching of the assumed role response is undesirable, use the --no-cache flag to disable caching of the assumed role response.

Example

$ awsassume -a arn:aws:iam::0123456789012:role/assume_role_test -n sessionname --no-cache

Region

The -r or --region option can be used to set the AWS_DEFAULT_REGION environment variable.

Example

$ awsassume -a arn:aws:iam::0123456789012:role/assume_role_test -n sessionname -r ap-southeast-1

Command

The -c or --command option can be used to pass the AWS CLI that is to be executed after successfully assuming role. The command will be executed with the following environment variables set to the credentials returned by the assumed role response.

  • AWS_ACCESS_KEY_ID

  • AWS_SECRET_ACCESS_KEY

  • AWS_SESSION_TOKEN

  • AWS_DEFAULT_REGION (only if the -r or --region option is set)

Example

$ awsassume -a arn:aws:iam::0123456789012:role/assume_role_test -n sessionname -c aws s3 ls

If the -c or --command option is omitted, the output of the program can be evaluated to export the following environment variables to the current shell.

  • AWS_ACCESS_KEY_ID

  • AWS_SECRET_ACCESS_KEY

  • AWS_SESSION_TOKEN

  • AWS_DEFAULT_REGION (only if the -r or --region option is set)

Example

$ `awsassume -a arn:aws:iam::0123456789012:role/assume_role_test -n sessionname`

Development

Clone the repository

$ git clone https://github.com/zulhilmizainuddin/aws-assume.git

Create and activate virtual environment

$ python -m venv ./venv
$ source ./venv/bin/activate

Install into development environment

$ python setup.py develop

Run unit test with pytest

$ python setup.py test

Run typing checking with mypy

$ mypy awsassume

Publishing to PyPI

Create source and binary distribution

$ python setup.py sdist bdist_wheel

Upload to PyPI

$ twine upload dist/*

Metadata

Release files for awsassume 0.1.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 awsassume 0.1.1
File Size Uploaded
awsassume-0.1.1.tar.gz 6.3 kB Details

Built distribution (wheel)

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

Total release size: 19.0 kB

Release files / awsassume-0.1.1.tar.gz

Download URL awsassume-0.1.1.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c1e1dacfd9e9e7de745d3b12bf41a9ceb70bfce6b3c9f879d7c44ca045cfcf23
BLAKE2b-256 checksum
How to use checksums
c2cb4cbc3e674877d2b204b8f05241da8d83a57679f3cbedfe8439e2e6ee2dc4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / awsassume-0.1.1-py3-none-any.whl

Download URL awsassume-0.1.1-py3-none-any.whl
Size 12.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f8c342c955382f374826413610206140fe00b87c050d8f99b8cc730257076968
BLAKE2b-256 checksum
How to use checksums
fd83642b6c19498ff4fa7d25afc7caa0b91f2c2e3396881b48277c89faff8b6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.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