Help us understand the problem. What is going on with this article?

[Proposal] Let AWS CLI run on Docker container

More than 1 year has passed since last update.

This article is an automatic translation of the article[341404aa6792ad4a9980] below.

What I did

The AWS CLI is executed on the Docker container, and only the result is returned to the terminal of the host OS.
By aliasing a series of processes including the Docker command, you can use AWS CLI as if it is running on the terminal of the host OS.


-It is not necessary to install Python, pip, AWS CLI, credentials to the host OS (do not pollute the host OS)
-Containerized, it is possible to distribute the unified AWS CLI environment to development members


Alpine and AWS CLI versions are hard-coded, so please change them manually.

FROM alpine:3.9
RUN apk -v --update add \
        python \
        py-pip \
        groff \
        less \
        mailcap \
        && \
    pip install --upgrade awscli==$AWS_CLI_VERSION python-magic && \
    apk -v --purge del py-pip && \
    rm /var/cache/apk/*

WORKDIR /project


docker build -t aws-cli .


Register access key ID, secret access key and default region in variables.

-For Windows (powershell)


-For Linux

export AWS_ACCESS_KEY_ID="<id>"
export AWS_SECRET_ACCESS_KEY="<key>"
export AWS_DEFAULT_REGION="<region>"


Create an alias to make the AWS CLI appear to be running on your host OS.
It is useful to register to"$profile"on Windows and".bash_profile"on Linux.
※ Mount the current directory to the work directory"/project"on the container.

-For Windows (powershell)

function aws(){
    docker run --rm -it `
    -v ${pwd}:/project `
    speaktech/aws-cli `

-For Linux

alias aws='docker run --rm -t $(tty &>/dev/null && echo "-i") \
-v "$(pwd):/project" \

How to use

The usage is the same as installing AWS CLI on the host OS. However, please note that command completion can not be performed.

aws s3 ls
aws s3 cp test.txt s3://test-bucket/test-prefix/ 
  • Since the current directory is mounted on the work directory"/project"on the container, files on the current directory can be copied.

Articles I've provided for reference

-AWS CLI in Docker
-AWS CLI in Docker environment

AWSが好きなインフラ屋さんです。 検証結果や作ったものを紹介していきます。 LGTMをいただけると、励みになります。記事内容にご意見・ご質問等があれば、全て回答しますのでコメントをお寄せください!
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away