Prerequisites:
- Familarity with Docker, Linux, and AWS CLI
- AWS Account (Do not use your root account!!!)
Today we will discuss how to use the AWS CLI via Docker.
Ensure your AWS CLI and Docker are installed and configured
Copy the following alias to your .bashrc, .zshrc, etc:
aws () {
docker run -it --rm \
--net=host \
-v `pwd`:/cfg -v ~/.aws:/home/awsuser/.aws \
-e AWS_REGION=$AWS_REGION -e AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION \
-e AWS_PAGER=$AWS_PAGER -e AWS_CLI_AUTO_PROMPT=$AWS_CLI_AUTO_PROMPT \
-e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
richarvey/awscli:latest"$@"
;
}
Refresh your shell:
. ~/.bashrc or . ~/.zshrc
Now you can run aws cli commands without having to install the binary. Users running this for the first time will see Docker download the image before executing the command. The image referenced in the function is a slimmed down image.
Try it out:
$ aws get-caller-identity #lists UserID, Account # and user ARN
I will be releasing videos to accompany each article at a later time, be on the lookout!