AWS CLI v2 for Python
Wrapper for AWS CLI v2.
Features
- No dependency hell, like with original awscli
- Can install and update
awscliv2binaries - Provides access to all AWS services
- Has Python interface
awscliv2.api.AWSAPI
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- InstallAWS CLI v2awsv2 --configure <profile_name> <aws_access_key_id> <aws_secret_access_key> [<aws_session_token>] [<region>]- set profile in~/.aws/credentialsawsv2 --assume-role <profile_name> <source_profile> <role_arn>- create a new profile with assume role credentialsawsv2 -V/--version- Outputawscliv2andAWS CLI v2versions
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="my_profile",
aws_access_key_id="access_key",
aws_secret_access_key="secret_key",
region="us-east-1",
)
aws_api.assume_role(
profile_name="my_profile",
source_profile="source_profile",
role_arn="role_arn",
)
Development
- Install poetry
- Run
poetry install - Use
blackformatter 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.
Release files for awscliv2 2.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| awscliv2-2.3.1.tar.gz | 12.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| awscliv2-2.3.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.6 kB
Release files / awscliv2-2.3.1.tar.gz
| Download URL | awscliv2-2.3.1.tar.gz |
|---|---|
| Size | 12.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5fbbf104bcd7796b7af104bd6af99f6e153208883399aeff830d97b3ea34f7ae
|
|
BLAKE2b-256 checksum How to use checksums |
a21d98a80461aad567164033e99780d31165626e57c8a86e668077f80e512a5e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.12
|
Release files / awscliv2-2.3.1-py3-none-any.whl
| Download URL | awscliv2-2.3.1-py3-none-any.whl |
|---|---|
| Size | 13.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ab4bc182b0cfba0f6872061cbb1bd6abfbfc1e4016fa5de40b7a2d564eca267e
|
|
BLAKE2b-256 checksum How to use checksums |
ddb6be25b1ddf45e9c73fdd26e95daa2892742932dc7c602844822c1fff5dab3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.12
|