如何在 amazon linux 容器上运行 aws cli?

如何在 amazon linux 容器上运行 aws cli?

我想将 amazon linux 命令作为 gitlab 管道的一部分运行。

因此,尝试使用 docker 镜像作为运行器,amazonlinux:最新

因此,连接到docker容器并运行以下命令。

yum -yq install aws-cli

它安装了 aws-cli

然后,配置aws cli。

aws configure set region $AWS_REGION
aws configure set aws_access_key_id $AWS_ACCESS_KEY
aws configure set aws_secret_access_key $AWS_SECRET_KEY
aws configure set plugins.bolt awscli-plugin-bolt

然后运行以下命令来检查身份,但由于 aws-cli-plugin-bolt 不存在而出现错误。

aws sts get-caller-identity

然后运行 ​​python pip install 并得到 python 2.7 弃用错误和未找到模块。

pip install awscli-plugin-bolt
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip install --user` instead.
ERROR: Could not find a version that satisfies the requirement awscli-plugin-bolt (from versions: none)
ERROR: No matching distribution found for awscli-plugin-bolt

因此,使用以下命令和参考将 Python 更改为 Python 3 作为默认版本

amazon-linux-extras enable python3.8
yum install python3.8
update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1

然后使用 pip3 安装 bolt 插件。

yum install python3-pip
pip3 install awscli-plugin-bolt

但是,下面的命令仍然在寻找 python 2 并且失败。

aws sts get-caller-identity

因此,删除该容器并创建一个新容器,并将该新容器作为第一步,将 python 版本 3 更改为默认版本。

但这次,yum 安装 aws-cli 本身失败了。

 bash-4.2# yum -yq install aws-cli
  File "/usr/bin/yum", line 30
    except KeyboardInterrupt, e:
                            ^
SyntaxError: invalid syntax

请建议如何从 amazonlinux docker 镜像访问 aws cli 命令。

如果我将图像更改为

  image: 
    name: amazon/aws-cli
    entrypoint: [""]

这样就不需要自己安装 aws cli 了。但是它默认自带 3.7,如何将其作为镜像的一部分进行更改。主要问题是,在 gitlab 中,上面的镜像可以正常工作,但使用 docker run 时,我无法直接使用该镜像。只有单个 aws 命令可以立即接受并关闭容器

相关内容