Skip to main content

Wrapper for AWS CLI v2

Project description

AWS CLI v2 for Python

PyPI - awscliv2 PyPI - Python Version PyPI - Downloads

Wrapper for AWS CLI v2.

Before you start

  • This is not an official AWS CLI v2 application, rant there
  • Check the source code of this app, as you are working with sensitive data
  • By default this app uses amazon/aws-cli Docker image
  • To use binaries for your OS, run awsv2 --install
  • Cross-check the source code again, probably I want to steal your credentials

Installation

python -m pip install awscliv2

You can add an alias to your ~/.bashrc or ~/.zshrc to use it as a regular AWS CLI v2

alias aws='awsv2'

Usage

From command line

Install AWS CLI v2:

# do not worry if this fails, you can still use awsv2 if you have docker installed
awsv2 --install

Configure default profile if needed:

AWS_ACCESS_KEY_ID='my-access-key'
AWS_SECRET_ACCESS_KEY='my-secret-key'

# --configure <profile_name> <aws_access_key_id> <aws_secret_access_key> [<aws_session_token>]
awsv2 --configure default ${AWS_ACCESS_KEY_ID} ${AWS_SECRET_ACCESS_KEY}
awsv2 configure set region us-west-1

Use AWS CLI as usual:

# alias for
# docker run --rm -i -v ~/.aws:/root/.aws -v $(pwd):/aws amazon/aws-cli $@
awsv2 s3 ls

# or as a python module
python -m awscliv2 s3 ls

Also, you can check scripts/example.sh

Docker fallback

Unless you run awsv2 --install once, application will use amazon/aws-cli Docker image. The image is not ideal, and it uses root user, so fix downloaded file permissions manually. Or just run awsv2 --install

Update it with docker pull amazon/aws-cli.

Container uses two volumes:

  • $HOME/.aws -> /root/.aws - credentials and config store
  • $(cwd) -> /aws - Docker image workdir

Extra commands

awscliv2 contains a few commands to make your life easier, especially in CI or any non-TTY environment.

  • awsv2 -U/--update/--install - Install AWS CLI v2
  • awsv2 --configure <profile_name> <aws_access_key_id> <aws_secret_access_key> [<aws_session_token>] [<region>] - set profile in ~/.aws/credentials
  • awsv2 --assume-role <profile_name> <source_profile> <role_arn> - create a new profile with assume role credentials
  • awsv2 -V/--version - Output awscliv2 and AWS CLI v2 versions

As a Python module

Basic usage

from awscliv2.api import AWSAPI
from awscliv2.exceptions import AWSCLIError

aws_api = AWSAPI()

try:
    output = aws_api.execute(["s3", "ls"])
except AWSCLIError as e:
    print(f"Something went wrong: {e}")
else:
    print(output)

Install binaries for your OS from Python

from awscliv2.installers import install_multiplatform

install_multiplatform()

You can also set credentials or assume roles

from awscliv2.api import AWSAPI

aws_api = AWSAPI()

aws_api.set_credentials("profile_name", "access_key", "secret_key", "", "region")
aws_api.assume_role("name", "source_profile", "role_arn")

Development

  • Install poetry
  • Run poetry install
  • Use black formatter in your IDE

How to help

  • Ping AWS team to release an official PyPI package
  • Share your experience in issues

Versioning

awscliv2 version follows PEP 440.

Latest changes

Full changelog can be found in Releases.

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

awscliv2-2.2.0.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

awscliv2-2.2.0-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file awscliv2-2.2.0.tar.gz.

File metadata

  • Download URL: awscliv2-2.2.0.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for awscliv2-2.2.0.tar.gz
Algorithm Hash digest
SHA256 941395c74eec75da44987930772102d7353090bf3e52681f20c5122abc66313c
MD5 b4c4b960ff095e0dea76699b4b273eb2
BLAKE2b-256 a4523a846215b4969c20b8e60f25a8cd373c367b5ebec12da5975f55e6e965c7

See more details on using hashes here.

File details

Details for the file awscliv2-2.2.0-py3-none-any.whl.

File metadata

  • Download URL: awscliv2-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for awscliv2-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 78de01b4d7a996da97b88c06197ba6cf3d9cbc0d15cc25289d34daa70c65dee5
MD5 3fa860b7181594a723f61e8474b2086a
BLAKE2b-256 8eb0507b940b0e6f9b54592ddc55e5b1895127f9d1cc54764deff124a0efbc07

See more details on using hashes here.

Supported by

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