Registry / aws / awscliv2

awscliv2

JSON →
library2.3.1pypypi✓ verified 22d ago

awscliv2 is a Python wrapper designed to provide a programmatic interface for interacting with the AWS CLI v2. It allows Python applications to execute AWS CLI commands, parse their output, and manage AWS resources without directly invoking shell commands. The library supports installing and updating the underlying AWS CLI v2 binaries or utilizing a Docker fallback. It is actively maintained, with the current version being 2.3.1.

pip install awscliv2
INSTALL
IMPORT
SIG · AWSCLIV2
A
awscliv2
awspythonv2.3.1
Install
1.5s avg
Import
69ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.3.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.070s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.068s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AWSAPI
from awscliv2.api import AWSAPI
AWSCLIError
from awscliv2.exceptions import AWSCLIError
Import for handling specific exceptions raised by AWS CLI commands.

This quickstart demonstrates how to initialize the `AWSAPI` client and execute a basic AWS CLI command, such as listing S3 buckets. Ensure your AWS credentials are configured either via environment variables (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_REGION`) or by running `awsv2 --configure` previously. The `AWSCLIError` is recommended for catching CLI-specific issues.

import os from awscliv2.api import AWSAPI from awscliv2.exceptions import AWSCLIError # AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY should be set as environment variables # or configured via `awsv2 --configure` for the underlying AWS CLI to pick them up. # Example: os.environ['AWS_ACCESS_KEY_ID'] = 'YOUR_ACCESS_KEY' # Example: os.environ['AWS_SECRET_ACCESS_KEY'] = 'YOUR_SECRET_KEY' aws_api = AWSAPI() try: # List S3 buckets output = aws_api.execute(['s3', 'ls']) print('S3 Buckets:\n', output) # Describe EC2 instances (example, might require specific region/permissions) # output = aws_api.execute(['ec2', 'describe-instances']) # print('EC2 Instances:\n', output) except AWSCLIError as e: print(f"AWS CLI Error: {e.return_code} - {e.stderr}") except Exception as e: print(f"An unexpected error occurred: {e}")
aws --version
Debug
Known issues
breakingPython 3.6 support was removed in version 2.0.0. Projects using older Python versions must upgrade to Python 3.7 or newer to use awscliv2 >= 2.0.0.
fix
Upgrade your Python environment to 3.7 or a later compatible version.
affects: >=2.0.0
gotchaThis library is an unofficial wrapper for the AWS CLI v2, not an official AWS SDK or an official AWS-published PyPI package. Users should be aware of this distinction and verify its suitability for their security requirements.
fix
Review the source code and ensure it meets your project's security and reliability standards.
affects: All versions
gotchaBy default, the library uses the `amazon/aws-cli` Docker image to run AWS CLI commands if the native AWS CLI v2 binary is not installed via `awsv2 --install`. Using Docker may involve running as a root user and could require manual permission adjustments for downloaded files.
fix
For production or performance-critical environments, consider installing the native AWS CLI v2 binary using `awsv2 --install` and ensure Docker permissions are properly managed if relying on the Docker fallback.
affects: All versions
gotchaIn versions prior to 2.3.1, `AWSAPI.execute` would raise an exception on a non-zero status code, and specific issues existed with output handling on Windows and `AWSAPI.assume_role` parsing. While fixed in 2.3.1, users on older versions may encounter these issues.
fix
Upgrade to awscliv2 version 2.3.1 or later to benefit from improved error handling and output parsing robustness, especially on Windows or when using `assume_role`.
affects: <2.3.1
Errors
Common errors & fixes
aws: command not found
The AWS CLI executable is not found in the system's PATH.
fix
Ensure the AWS CLI is installed and add its installation directory to the PATH environment variable.
aws : The term 'aws' is not recognized as the name of a cmdlet, function, script file, or operable program.
PowerShell cannot locate the AWS CLI executable, possibly due to it not being installed or not being in the system's PATH.
fix
Install the AWS CLI and add its installation path to the system's PATH environment variable.
ModuleNotFoundError: No module named 'awscliv2'
The 'awscliv2' Python package is not installed in the current environment.
fix
Install the 'awscliv2' package using pip: 'pip install awscliv2'.
ImportError: cannot import name 'AWSAPI' from 'awscliv2.api'
The 'AWSAPI' class is not available in the 'awscliv2.api' module, possibly due to an outdated version of the package.
fix
Update the 'awscliv2' package to the latest version using pip: 'pip install --upgrade awscliv2'.
AttributeError: module 'awscliv2' has no attribute 'execute'
The 'execute' function does not exist in the 'awscliv2' module, indicating incorrect usage or a missing method.
fix
Refer to the 'awscliv2' documentation to use the correct methods for executing AWS CLI commands.
Upgrade
Version history
2.3.1latest on PyPI · released Sep 4, 2024
Audit
Dependencies
pythonrequiredRequires Python 3.7 or newer, but less than 4.0 for compatibility.
aws-clirequiredThis library is a wrapper around the official AWS CLI v2. The underlying 'aws' binary or the 'amazon/aws-cli' Docker image is a fundamental runtime dependency.
dockeroptionalUsed as a fallback mechanism if the AWS CLI v2 binary is not installed via 'awsv2 --install'.
Agent activity
26 hits · last 30 days
node
20
OpenAI (training)
2
Resources
awscliv2 — pip install awscliv2 · libregistry