-
Notifications
You must be signed in to change notification settings - Fork 2
Simpler way to use your AWS credentials in Docker #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
housni
wants to merge
2
commits into
ysfiqbl:master
Choose a base branch
from
housni:feature/easier-aws-cli-access
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" ] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ``` |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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-userwill run, by default.