Skip to content
wordpress meta

title: 'Using AWS CLI Docker image'
date: '2020-03-21T08:25:31-05:00'
status: publish
permalink: /using-aws-cli-docker-image
author: admin
excerpt: ''
type: post
id: 1471
    - Docker
tag: []
post_format: []

Recording my test running AWS CLI in a docker image.


get a base ubuntu image

docker pull ubuntu

Using default tag: latest latest: Pulling from library/ubuntu ...

install the Aws CLI and commit to a image

docker run -it --name awscli ubuntu /bin/bash

root@25b777958aad:/# apt update root@25b777958aad:/# apt upgrade root@25b777958aad:/# apt install awscli root@25b777958aad:/# exit

docker commit 25b777958aad awscli


alias to run a docker image with cli commands

alias awscli=docker run -it --name aws-iqonda --rm -e AWS_DEFAULT_REGION='us-east-1' -e AWS_ACCESS_KEY_ID='<...>' -e AWS_SECRET_ACCESS_KEY='<...>' --entrypoint aws awscli

awscli s3 ls | grep ls-al

2016-02-17 15:43:57

awscli ec2 describe-instances --query 'Reservations[].Instances[].[InstanceId,Tags[?Key==Name].Value|[0],State.Name,PrivateIpAddress,PublicIpAddress]' --output text

i-0e38cd17dfed16658 ec2server running

one way to hide key variables with pass/gpg

$ pass init email@addr.ess $ pass insert awscreds-iqonda/aws-access-key-id $ pass insert awscreds-iqonda/aws-secret-access-key

$ pass Password Store └── awscreds-iqonda ├── aws-access-key-id └── aws-secret-access-key

$ pass awscreds-iqonda/aws-access-key-id <...> $ pass awscreds-iqonda/aws-secret-access-key <...>

$ export AWS_ACCESS_KEY_ID=$(pass awscreds-iqonda/aws-access-key-id) $ export AWS_SECRET_ACCESS_KEY=$(pass awscreds-iqonda/aws-secret-access-key)

** TODO: how to batch this? this is fine for desktop use but I do not want a gpg keyring password prompt either text or graphic in a server scripting situation. Maybe look at hashicorp vault?


for convenience use an alias

$ alias awscli=sudo docker run -it --name aws-iqonda --rm -e AWS_DEFAULT_REGION='us-east-1' -e AWS_ACCESS_KEY_ID='$AWS_ACCESS_KEY_ID' -e AWS_SECRET_ACCESS_KEY='$AWS_SECRET_ACCESS_KEY' --entrypoint aws awscli

$ awscli s3 ls ````

Some useful References: