Score:0

How to run aws cli on amazon linux container?

ke flag

I want to run amazon linux commands as part of gitlab pipeline.

So, trying to use docker image as runner, amazonlinux:latest

So, connected to docker container and ran below command.

yum -yq install aws-cli

It installed aws-cli

Then, configured 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

Then ran below command to check identity, but got error as aws-cli-plugin-bolt not there.

aws sts get-caller-identity

Then ran python pip install for the same and got python 2.7 deprecation error and module not found.

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

So changed the python to python 3 as default version using below commands and the reference page.

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

And then installed the bolt pluging using pip3.

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

But still, below command still looks for python 2 and failing.

aws sts get-caller-identity

So, deleted that container and created a new one and in that as first step, changed the python version 3 as default one.

But this time, yum installation of aws-cli itself failing.

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

Please suggest how to access aws cli commands from the amazonlinux docker image.

It seems it is working if I change the image to

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

So that no need to install aws cli on my own. But it is coming with 3.7 by default, how to change that as part of image. And major question, in gitlab above image is working, with docker run I wasn't able to use the image directly. Only individual aws commands it is accepting and closing the container immediately

Tim avatar
gp flag
Tim
I don't think AWS CLI v2 is installed by yum. Try installing it manually. Make sure you check the version after it's installed to make sure you're using CLI v2.x https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.