Post

AWS Configuration Quick Reference

AWS Configuration Quick Reference

What is it?

Quick reference guide for AWS configuration and common setup tasks. Copy-paste ready commands and snippets.

AWS CLI Setup

Installation & Basic Configuration

1
2
3
4
5
6
7
8
9
10
11
# Install AWS CLI v2
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

# Configure default profile
aws configure
# AWS Access Key ID: YOUR_ACCESS_KEY
# AWS Secret Access Key: YOUR_SECRET_KEY
# Default region: us-east-1
# Default output format: json

Multiple Profiles

Set one profile for terminal and type chaws to choose AWS profile.

1
2
chaws 
aws configure

Code (~/.bashrc)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
AWS_PROFILES=( $(aws configure list-profiles) )
PROFILE=$(echo "${AWS_PROFILES[0]}")
echo "Selected profile: |$PROFILE|"
export AWS_PROFILE=$PROFILE
export AWS_DEFAULT_PROFILE=$PROFILE

# Change AWS Profile
chaws() {
    AWS_PROFILES=($(aws configure list-profiles))

    if [[ ${#AWS_PROFILES[@]} -eq 0 ]]; then
        echo "No AWS profiles found"
        return 1
    fi

    printf "\n!!Configured AWS Profiles:\n"
    for i in "${!AWS_PROFILES[@]}"; do
        echo "$((i + 1)): ${AWS_PROFILES[i]}"
    done

    printf "\nEnter profile number: "
    read -r choice

    # Validate input is a number and within range
    if ! [[ "$choice" =~ ^[0-9]+$ ]] || [[ $choice -lt 1 ]] || [[ $choice -gt ${#AWS_PROFILES[@]} ]]; then
        echo "Invalid selection"
        return 1
    fi

    PROFILE=$(echo "${AWS_PROFILES[choice-1]}" | xargs)
    echo "Selected profile: |$PROFILE|"
    export AWS_PROFILE=$PROFILE
    export AWS_DEFAULT_PROFILE=$PROFILE
    printf "\nAWS profile set to \"%s\"\n" "$AWS_PROFILE"
}

Troubleshooting

Common Issues

1
2
3
4
5
6
7
8
9
10
11
# Check current identity
aws sts get-caller-identity

# Verify region
aws configure get region

# Test connectivity
aws s3 ls

# Debug with verbose output
aws s3 ls --debug
This post is licensed under CC BY 4.0 by the author.