- 最新
- 投票最多
- 评论最多
It seems like there are two issues you're facing: The environment from which Jenkins is running the shell script can't find the AWS CLI (hence "aws: command not found"). There's a Python issue regarding awscli.clidriver.
Here are the steps to resolve these issues:
Solution 1: Correct Path
The AWS CLI might be installed in a location that's not in your PATH. Jenkins might not be using the same environment variables as your user, so it doesn't know where to find the AWS CLI.
To resolve this, you can specify the full path to the AWS CLI executable in your script. But before you can do this, you must find the correct path where AWS CLI is installed.
To find the path, you can use the command: which aws
This command will return the full path of AWS CLI. Once you have this, replace "aws" in your script with the full path.
Solution 2: Jenkins User Permissions
If AWS CLI is installed for a specific user, ensure the Jenkins job is running as that user, or install AWS CLI as a root user or Jenkins user, depending on your security considerations.
You can use the following commands to install AWS CLI for all users:
curl "https://d1vvhvl2y92vvt.cloudfront.net/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
Solution 3: Python Environment
Your second error indicates a Python environment problem. The AWS CLI is written in Python, so if there's an issue with your Python installation or environment, it could cause issues with the AWS CLI.
If the AWS CLI was installed with pip, try reinstalling it using pip: pip install awscli --upgrade --user
If you have multiple versions of Python installed, make sure you're using the correct version of pip that matches the Python version the AWS CLI is using. You can check the Python version with: python --version
and the pip version with: pip --version
Also, make sure that your Python's scripts path is in your PATH environment variable.
Solution 4: Ansible AWS Modules
Instead of using AWS CLI commands in a shell script, consider using Ansible's built-in AWS modules, which are designed for managing AWS resources. This will handle AWS API calls for you, and you don't have to worry about managing AWS credentials or the AWS CLI. You can refer to the (Ansible AWS Guide)[https://docs.ansible.com/ansible/latest/scenario_guides/guide_aws.html] for more information.
Remember that these fixes address the issues separately. If your issue is caused by a combination of them, you may need to apply multiple fixes.
相关内容
- AWS 官方已更新 1 年前
I was not able to reinstall using pip install awscli --upgrade --user (ConnectTimeoutError)