This is dockerized version of the awscli, which means you can run the tool without directly installing it on your system. It's simple to map your AWS credentials to this container and even set up a .bash_profile so you can just type aws
in the command line. The image is auto-built daily to ensure the Linux base image is constantly updated in the background and that you have the latest awscli version.
I've finally made a unified version which is super slim and from version 2.2.10
it's a mere 97.6Mb and is based upon alpine Linux (yes all the musl libc and OpenSSL issues are taken care of) add to this it is available on both x86_64 and arm64.
Tags and releases are in line with the AWS CLI version, so you can use that to pull a specific release if needed for example: 2.2.6
Amazon provides a container for this already, it's good but it weighed in a little heavy for me at ~387MB. I wanted this as small as possible and managed to shave off ~290MB on the uncompressed image.
Why else?
Well, I've been doing this since version 1.6.x and I trust my image builds, I know they are lightweight and no bloat. Switching from debian-slim to Alpine Linux has allowed me to make this even smaller so I'm super happy with that.
docker pull richarvey/awscli:latest
See all tags at https://hub.docker.com/r/richarvey/awscli/tags/
Running in the normal mode gives the CLI tools access to your current working directory and your AWS credentials (potentially ~/.aws). Its controlled by specifying -v `pwd`:/cfg -v ~/.aws:/home/awsuser/.aws on the command line. This will be the mode used in all the examples. This is great for limiting the reach of the toolkit onto your system. You'll share your AWS credentials and the current working directory so you can use the CloudFormation file you've been working on or tell S3 to upload/download files.
To give you more access to files outside your current working directory you can swap -v `pwd`:/cfg -v ~/.aws:/home/awsuser/.aws for -v ~/:/home/awsuser. This gives docker access to your entire home directory including your docker credentials.
NOTE: I recommend running these as bash alias' in order to make it a smooth process of using this toolkit and save a lot of typing.
Run the container and map a local directory (for files you may want to use) and .aws config for credentials
docker run -it -v `pwd`:/cfg -v ~/.aws:/home/awsuser/.aws richarvey/awscli:latest ${COMMAND}
Instead of including --profile SomeProfile
in each command you can also use the -e AWS_PROFILE=SomeProfile
in the docker command. This can be particularly useful when setting up your bash profile and allows us to use different alias' for different accounts. To run fromt he command line do the following:
docker run -it -e AWS_PROFILE=SomeProfile -v `pwd`:/cfg -v ~/.aws:/home/awsuser/.aws richarvey/awscli:latest ${COMMAND}
You can set an alias and then use awscli as normal from your shell if desired, this makes it super easy to access.
vi ~/.bash_profile
aws() {
docker run -it -v `pwd`:/cfg -v ~/.aws:/home/awsuser/.aws --rm richarvey/awscli:latest "$@";
}
Now when you call aws
from the command line (don't forget to source your bash_profile) you'll have direct access to the aws command as if it were installed on your system.
For advanced use and multiple profiles try something like the following:
vi ~/.bash_profile
# default account
aws() {
docker run -it -v `pwd`:/cfg -v ~/.aws:/home/awsuser/.aws --rm richarvey/awscli:latest "$@";
}
# Named profile account from .aws/config file
aws_profile_name() {
docker run -it -e AWS_PROFILE=SomeProfile -v `pwd`:/cfg -v ~/.aws:/home/awsuser/.aws --rm richarvey/awscli:latest "$@";
}
The build process is now super simple and you can build using the normal docker tools:
docker build -t MYBUILD .