Skip to content

Docker container for AWS CLI. Containerized AWS CLI using Alpine image to avoid requiring the AWS CLI to be installed on localhost and CICD pipelines.

License

Notifications You must be signed in to change notification settings

rommelporras/aws-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AWS CLI Docker Container

Docker Pulls Docker Stars

Supported tags, Dockerfile links, AWS Release Date

Run / Build

docker run -rm \
    --env AWS_ACCESS_KEY_ID=<<YOUR_ACCESS_KEY>> \
    --env AWS_SECRET_ACCESS_KEY=<<YOUR_SECRET_ACCESS>> \
    rommelporras/aws-cli \
    s3 ls

or

docker build -t rommelporras/aws-cli:latest .

Description

Docker container with the AWS CLI installed.

Using Alpine linux. The Docker image is 49MB

An automated build of this image is on Docker Hub: https://hub.docker.com/r/rommelporras/aws-cli/

Install

Configure:

export AWS_ACCESS_KEY_ID="<awsid>"
export AWS_SECRET_ACCESS_KEY="<awskey>"
export AWS_DEFAULT_REGION="eu-west-1"

alias aws='docker run --rm -t $(tty &>/dev/null && echo "-i") -e "AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}" -e "AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}" -e "AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION}" -v "$(pwd):/project" rommelporras/aws-cli'

or

alias aws='docker run --rm -t $(tty &>/dev/null && echo "-i") -e "AWS_ACCESS_KEY_ID=AKIA2XXXXXXXXX" -e "AWS_SECRET_ACCESS_KEY=q/z4m+jgXXXXXXXXXX" -e "AWS_DEFAULT_REGION=eu-west-1" -v "$(pwd):/project" rommelporras/aws-cli'

Example Usage:

Describe an instance:

docker run -rm \
--env AWS_ACCESS_KEY_ID=<<YOUR_ACCESS_KEY>> \
--env AWS_SECRET_ACCESS_KEY=<<YOUR_SECRET_ACCESS>> \
--env AWS_DEFAULT_REGION=us-east-1 \
rommelporras/aws-cli \
ec2 describe-instances --instance-ids i-90949d7a

or

aws ec2 describe-instances --instance-ids i-90949d7a #apply alias first

output:

{
    "Reservations": [
        {
            "OwnerId": "960288280607",
            "ReservationId": "r-1bb15137",
            "Groups": [],
            "RequesterId": "226008221399",
            "Instances": [
                {
                    "Monitoring": {
                        "State": "enabled"
                    },
                    "PublicDnsName": null,
...
...
}

Example Usage with Docker Compose:

First: Update the environment credentials in docker-compose.yml

docker-compose run aws s3 ls

output:

2019-10-17 13:07:17 sftp-bucket-ips
2019-04-30 09:48:13 rommelporras-dev-bucket

Return a list of items in s3 bucket

docker run -rm \
--env AWS_ACCESS_KEY_ID=<<YOUR_ACCESS_KEY>> \
--env AWS_SECRET_ACCESS_KEY=<<YOUR_SECRET_ACCESS>> \
rommelporras/aws-cli \
s3 ls

output:

2019-12-19 01:41:30 Assets
2014-06-06 01:02:29 Layouts

Upload content of your current directory (say it contains two files test.txt and test2.txt) to s3 bucket

docker run -rm \
--env AWS_ACCESS_KEY_ID=<<YOUR_ACCESS_KEY>> \
--env AWS_SECRET_ACCESS_KEY=<<YOUR_SECRET_ACCESS>> \
-v $PWD:/data \
rommelporras/aws-cli \
s3 sync . s3://mybucketname

output:

(dryrun) upload: test.txt to s3://mybucketname/test.txt
(dryrun) upload: test2.txt to s3://mybucketname/test2.txt

doc: http://docs.aws.amazon.com/cli/latest/reference/s3/index.html

Retrieve a decrypted Windows password by passing in your private key

We will map the private keys that resides on your local system to inside the container

docker run -rm \
-v <<LOCATION_TO_YOUR_PRIVATE_KEYy>>:/tmp/key.pem \
--env AWS_ACCESS_KEY_ID=<<YOUR_ACCESS_KEY>> \
--env AWS_SECRET_ACCESS_KEY=<<YOUR_SECRET_ACCESS>> \
--env AWS_DEFAULT_REGION=us-east-1 \
rommelporras/aws-cli \
ec2 get-password-data --instance-id  <<YOUR_INSTANCE_ID>> --priv-launch-key /tmp/key.pem

Output:

{
    "InstanceId": "i-90949d7a",
    "Timestamp": "2014-12-11T01:18:27.000Z",
    "PasswordData": "8pa%o?foo"
}

doc: http://docs.aws.amazon.com/cli/latest/reference/ec2/get-password-data.html

Getting your AWS Keys:

http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-set-up.html#cli-signup

Passing your keys into this container via environmental variables:

http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-environment

Command line options for things like setting the region

http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-command-line

You can run any commands available to the AWS CLI

http://docs.aws.amazon.com/cli/latest/index.html

About

Docker container for AWS CLI. Containerized AWS CLI using Alpine image to avoid requiring the AWS CLI to be installed on localhost and CICD pipelines.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published