Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .env

This file was deleted.

6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
aws/
# Contains environment variables to be passed into Docker.
# Allows `env.sample` to be tracked but not any other file beginning with `env.`
# For example, `env.dev` or `env.prod` won't be tracked but `env.sample` will.
env.*
!env.sample
18 changes: 9 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
FROM python:3.7-slim
FROM alpine:3.8
MAINTAINER Yusuf Iqbal <yusuf.iqbal@devfactory.com>

RUN apt-get update
RUN apt-get install --no-install-suggests -y groff-base
RUN apk --update add --no-cache \
python \
py-pip \
&& pip install --upgrade awscli \
&& apk -v --purge del py-pip \
&& rm /var/cache/apk/*

# Set the application directory
WORKDIR /app

# Install AWS CLI
RUN pip install awscli --upgrade --user
RUN pip install --upgrade pip
ENV PATH=~/.local/bin:$PATH

# Copy code from the current folder to /app inside the container
ADD . /app

RUN cp -r /app/aws/ ~/.aws
ENTRYPOINT [ "aws" ]
CMD [ "iam", "get-user" ]
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, if the user doesn't provide an argument when calling docker run, iam get-user will run, by default.

52 changes: 50 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,50 @@
- `docker-compose build`
- `docker-compose run aws_cli bash`
# AWS CLI

Docker image to run AWS CLI commands without having to install it on the host system.

## Usage
Make a copy of the environment file.
```
$ cp env.sample env.dev # You can make it `env.prod` or anything you want.
```

Edit to add your own AWS credentials.
```
$ vim env.dev
```

Build your Docker image:
```
$ docker build \
--rm \
-t aws_cli \
.
```

Run the `aws_cli_container` container off the `aws_cli` image, loading environment variables from the file `env.dev` into the container and specify your AWS command at the end:
```
$ docker run \
--rm \
-it \
--name=aws_cli_container \
-v ${PWD}:/app \
--env-file ./env.dev \
aws_cli \
iam get-user
```

You can also create an alias for the Docker run command in your ~/.bashrc by adding this at the end:
```
alias aws='docker run --rm -it --name=aws_cli_container -v ${PWD}:/app --env-file ./env.dev aws_cli'

```

Then, source the file:
```
$ . ~/.bashrc
```

Then, you can just do:
```
$ aws iam get-user
```
10 changes: 0 additions & 10 deletions docker-compose.yml

This file was deleted.

14 changes: 14 additions & 0 deletions env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
COMPOSE_PROJECT_NAME=aws_cli

# References:
# 1. https://docs.docker.com/engine/reference/commandline/run/#set-environment-variables--e---env---env-file
# 2. https://docs.aws.amazon.com/cli/latest/userguide/cli-environment.html
# 3. https://docs.aws.amazon.com/cli/latest/topic/config-vars.html

# Access and secret key variables override credentials stored in credential and config files.
AWS_ACCESS_KEY_ID=***REMOVED***
AWS_SECRET_ACCESS_KEY=***REMOVED***

# AWS region. This variable overrides the default region of the in-use profile, if set.
# See: https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/
AWS_DEFAULT_REGION=us-west-2