{"id":4890,"library":"awscliv2","title":"AWS CLI v2 Python Wrapper","description":"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.","status":"active","version":"2.3.1","language":"en","source_language":"en","source_url":"https://github.com/youtype/awscliv2","tags":["aws","cli","wrapper","cloud","automation","devops"],"install":[{"cmd":"pip install awscliv2","lang":"bash","label":"Install awscliv2 Python package"},{"cmd":"awsv2 --install","lang":"bash","label":"Install underlying AWS CLI v2 binary (optional, defaults to Docker)"}],"dependencies":[{"reason":"Requires Python 3.7 or newer, but less than 4.0 for compatibility.","package":"python","optional":false},{"reason":"This 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.","package":"aws-cli","optional":false},{"reason":"Used as a fallback mechanism if the AWS CLI v2 binary is not installed via 'awsv2 --install'.","package":"docker","optional":true}],"imports":[{"symbol":"AWSAPI","correct":"from awscliv2.api import AWSAPI"},{"note":"Import for handling specific exceptions raised by AWS CLI commands.","symbol":"AWSCLIError","correct":"from awscliv2.exceptions import AWSCLIError"}],"quickstart":{"code":"import os\nfrom awscliv2.api import AWSAPI\nfrom awscliv2.exceptions import AWSCLIError\n\n# AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY should be set as environment variables\n# or configured via `awsv2 --configure` for the underlying AWS CLI to pick them up.\n# Example: os.environ['AWS_ACCESS_KEY_ID'] = 'YOUR_ACCESS_KEY'\n# Example: os.environ['AWS_SECRET_ACCESS_KEY'] = 'YOUR_SECRET_KEY'\n\naws_api = AWSAPI()\ntry:\n    # List S3 buckets\n    output = aws_api.execute(['s3', 'ls'])\n    print('S3 Buckets:\\n', output)\n\n    # Describe EC2 instances (example, might require specific region/permissions)\n    # output = aws_api.execute(['ec2', 'describe-instances'])\n    # print('EC2 Instances:\\n', output)\n\nexcept AWSCLIError as e:\n    print(f\"AWS CLI Error: {e.return_code} - {e.stderr}\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade your Python environment to 3.7 or a later compatible version.","message":"Python 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.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Review the source code and ensure it meets your project's security and reliability standards.","message":"This 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"By 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.","severity":"gotcha","affected_versions":"All versions"},{"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`.","message":"In 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.","severity":"gotcha","affected_versions":"<2.3.1"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}