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

AWS CLIをDocker環境で実行する

More than 1 year has passed since last update.

やったこと

AWS CLI(1.16.76)とSAM(serverless application model)をDocker環境で実行できるようにする。

Dockerfile

FROM python:3.6

ARG pip_installer="https://bootstrap.pypa.io/get-pip.py"
ARG awscli_version="1.16.76"

# Install awscli
RUN pip install awscli==${awscli_version}

# Install sam
RUN pip install --user --upgrade aws-sam-cli
RUN mkdir /data
RUN chmod -x /data

ENV PATH $PATH:/root/.local/bin

※ awscli_versionはよしなに変えてください。

コンテナ起動

ビルド

docker build -t aws-cli .

コンテナの起動

AWS_ACCESS_KEY_ID="<your aws access key id>"
AWS_SECRET_ACCESS_KEY="<your aws access key>"
AWS_DEFAULT_REGION="<aws default region>"

docker run -it \
    -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
    -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
    -e AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION \
    -v $(pwd):/data \
    aws-cli /bin/bash

カレントディレクトリが/dataディレクトリにマウントされます。
docker内で指定したバージョンのCLI、SAMが使用できます。

試しにコンテナ内で

aws s3 ls

と打ってs3のバケット一覧が取得できればOKです。

終わりに

aws cliの環境を整えようとするとpythonやpipのバージョンを合わせたりが面倒だったので、コンテナで運用すると楽になりました。本番環境へのデプロイにも使えると思うので、ぜひ活用してみてください。

ABCompany1
AWS/React Opinions are my own, not endorsed by any org.
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
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  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
ユーザーは見つかりませんでした