Docker

Setup a Docker Container with the AWS CLI Tools

The AWS Command Line Interface (AWS CLI) is an open source tool that enables you to interact with AWS services using commands in your command-line shell.

With minimal configuration, the AWS CLI enables you to start running the commands that implement functionality equivalent to that provided by the browser-based AWS Management Console from the terminal.

In this quick tutorial, we will show you how to setup a Docker container that contains the AWS CLI tools. This allows you to quickly interact with AWS infrastructure from a Docker container.

Requirements:

To run the commands and steps provided in this post, ensure that you have the following:

    1. Installed Docker Engine
    2. Installed Docker Compose
    3. Sufficient permissions to run the Docker containers

With the given requirements met, we can proceed with the tutorial.

Docker Pull AWS CLI

The first step is to download the Docker AWS CLI image. We can use the “docker pull” command as follows:

$ docker pull amazon/aws-cli

 

Run the Docker Container

Once we pull the container, we can simply use the Docker CLI to quickly run the AWS CLI container using the following command:

$ docker run --rm -it amazon/aws-cli --version

 
The previous command should create a new container using the AWS CLI image and print out the version of the AWS CLI in the container.

Output:

aws-cli/2.13.19 Python/3.11.5 Linux/6.4.16-orbstack-00103-g02b40eb69695 docker/aarch64.amzn.2 prompt/off

 

Add the Command as Alias

In order to shorten the length of the Docker commands, you can add the command as alias as follows:

alias aws='docker run --rm -ti -v ~/.aws:/root/.aws -v $(pwd):/aws amazon/aws-cli'

 
You can then test it by running the command as “aws-cli”:

$ aws --version

 
You can learn more about the AWS CLI commands in the following resource:

https://aws.amazon.com/cli/

Conclusion

In this tutorial, we quickly outlined the steps of setting up a basic container with the AWS CLI tools. Feel free to check the documentation to learn more.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list