Skip to content

Instantly share code, notes, and snippets.

@aidmax
aidmax / gist:5d62c7319c2cace2f82f33423a274dc7
Last active September 13, 2022 19:01
Detect AWS region and account_id and save it to .bashrc
# Configure AWS CLI with the current region as default
echo "export AWS_DEFAULT_REGION=$(curl -s 169.254.169.254/latest/dynamic/instance-identity/document | jq -r .region)" >> ~/.bashrc
echo "export AWS_REGION=\$AWS_DEFAULT_REGION" >> ~/.bashrc
echo "export AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)" >> ~/.bashrc
source ~/.bashrc
# Verify that AWS_REGION is set correctly
test -n "$AWS_REGION" && echo AWS_REGION is "$AWS_REGION" || echo AWS_REGION is not set