Install AWS CLI in distrobox

· nat's blog


Create the distrobox:

1distrobox create \
2            --image ubuntu:latest \
3            -p \
4            --yes \
5            --name aws \
6            --home ~/.distrobox/aws

Now enter the distrobox distrobox enter aws, set password and start Installing AWS CLI on Ubuntu 24.04

1sudo apt update
2sudo apt install -y python3 python3-pip unzip
3curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
4unzip awscliv2.zip
5sudo ./aws/install
6distrobox-export --bin `which aws` --export-path ~/bin
7exit

So now we are outside of the distrobox and have an aws command in ~/.distrobox/aws/bin, where we might want to sudo cp -a ~/.distrobox/aws/bin/aws /usr/local/bin/aws.

Configure aws #

Create a "root" key with "IAM/Security.../Accesskey" and then enter this into aws configure. (Also copy/paste it somewhere for future reference))

1AWS Access Key ID [None]: 
2AWS Secret Access Key [None]: 
3Default region name [us-east-1]:
4Default output format [json]: 

Manage instances #

List instance and some interesting information:

1aws ec2 describe-instances | jq -r '.Reservations[].Instances[] |
2  [
3    (.Tags[] | select(.Key=="Name").Value // "No Name"),
4    .InstanceId,
5    .State.Name,
6    .InstanceType,
7    .PublicIpAddress
8  ] | @tsv' | sort

Start, halt, destroy an instance or multiple instances:

1aws ec2 start-instances --instance-ids <instance-id>
2aws ec2 stop-instances --instance-ids <instance-id>
3aws ec2 terminate-instances --instance-ids <instance-id>