Skip to content

aws cli v2 in python venv

0

I have the aws cli installed:

(.venv) ubuntu@ip-172-31-29-192:~/blw_dataviz_data$ aws --version
aws-cli/1.40.21 Python/3.12.3 Linux/6.8.0-1029-aws awscrt/0.23.8 botocore/1.38.22

And yet...

(.venv) ubuntu@ip-172-31-29-192:~/blw_dataviz_data$ aws configure sso
Note: AWS CLI version 2, the latest major version of the AWS CLI, is now stable and recommended for general use. For more information, see the AWS CLI version 2 installation instructions at: https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html

usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:

  aws help
  aws <command> help
  aws <command> <subcommand> help
aws: error: argument subcommand: Invalid choice, valid choices are:

list                                     | get                                     
set                                      | add-model                 

I think the problem is that I need to be running aws-cli v2. The trick is getting v2 installed in the python virtual environment I'm working in. AWS has docs about installing version 1 in a python venv, but not how to install v2 in a python venv.

Help?

asked a year ago867 views

2 Answers
0

You're correct that the issue is related to using AWS CLI version 1 instead of version 2. AWS CLI version 2 is indeed recommended for general use and is required for certain features like the SSO login you're attempting to use.

However, it's important to note that AWS CLI version 2 is not typically installed via pip or within a Python virtual environment. Instead, it's installed as a standalone application.

To resolve your issue, you have a couple of options:

  1. Install AWS CLI version 2 system-wide: You can download and install AWS CLI v2 following the official AWS instructions for your operating system. This will install it outside of your virtual environment, but it will be available system-wide.

  2. Use AWS CLI v2 alongside your virtual environment: After installing AWS CLI v2 system-wide, you can use it from within your virtual environment by specifying the full path to the AWS CLI v2 executable.

To install AWS CLI version 2 on a Linux system, you can use these commands:

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

After installation, you can verify the version by running:

aws --version

This should show you're using AWS CLI version 2.

Remember, even though you're working in a Python virtual environment, you'll be using the system-wide installation of AWS CLI v2. This is the recommended approach as AWS CLI v2 is not designed to be installed in a Python virtual environment.

If you need to use AWS SDK functionality within your Python code, you should use the boto3 library, which can be installed in your virtual environment using pip.
Sources
Community | Command Line Magic | S01 E03 | Build On Weekly
AWS CLI Adds PKCE-based Authorization for SSO | AWS Developer Tools Blog

answered a year ago

0

Hello.

Try installing from GitHub in a venv-enabled project directory as follows:

python3 -m pip install https://github.com/boto/botocore/archive/v2.tar.gz
python3 -m pip install https://github.com/aws/aws-cli/archive/v2.tar.gz

I checked the GitHub issues for AWS CLI, but it seems that there are currently no plans to release AWS CLI v2 on PyPI.
https://github.com/aws/aws-cli/issues/4947#issuecomment-793192340

EXPERT

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.