AWSCLI is the command line interface is unified utility that provides ability to programmers and DevOps to manage AWS infrastructure directly from the terminal. Currently the WS CLI v2 is available with the easily installation methods. This is widely supported tools available for most of popular platform like Linux, macOS and Windows systems. Alpine Linux is a simple, lightweight operating system that make is first choice for the containers that required minimal size.

Advertisement

This tutorial will help you install and configure AWS CLI v2 on an Alpine system running under Docker containers.

Alpine Dockerfile with AWSCLIv2

A Dockerfile is an text file contains the instructions to configure the containers. Docker engine read the instructions from this file and build a Docker image accordingly. Generally it is available under the root directory of project, but you can create anywhere in project.

Let’s create a file named “Dockerfile” under the root directory of your application:

touch Dockerfile 

Use your favorite text editor like nano or vim to edit the Dockerfile. We’ll use Alpine Linux as our base image due to its small size and security focus. Define the base image at the beginning of your Dockerfile then install Python, pip (a package manager for Python), and other dependencies required for AWSCLI.


FROM alpine:latest

RUN apk add --no-cache \
        python3 \
        py3-pip \
    && pip3 install --upgrade pip \
    && pip3 install --no-cache-dir awscli \
    && rm -rf /var/cache/apk/*

RUN aws --version   # Verify the installation

During the build process of docker image, the AWSCLI packages will be added to the Alpine container using given commands in Dockerfile.

Considerations for AWS Credentials

AWSCLI required the AWS credentials (generally a pair of access and secret key) to communicate with AWS services. It is highly recommended to not to save these keys to the Dockerfile or docker-compose.yaml files ever. Instead of that, you should consider passing these securely at runtime using environment variables or use AWS IAM roles if your containers are running within AWS, such as EC2 or ECS.

Wrapping Up

Assuming you find this article helpful for configuring the AWSCLI environment under containers. This is useful when the containers required to interact with AWS services at runtime. Remember never store your credentials under the text files that can be compromised. These keys are very sensitive and can be stolen easily. With the successful implementation of AWSCLI within an Alpine Dockerfile, you can now utilize this Docker image to manage AWS services via command-line from within a containerized environment.

Share.
Leave A Reply


Exit mobile version