region and profile handling improved

This commit is contained in:
Toni de la Fuente
2018-04-19 09:47:16 -04:00
parent ada8a225ae
commit 38ad3ca657
2 changed files with 15 additions and 2 deletions

View File

@@ -17,6 +17,9 @@
# instance profile (metadata server) if runs in an EC2 instance
INSTANCE_PROFILE=$(curl -s -m 1 http://169.254.169.254/latest/meta-data/iam/security-credentials/)
if echo "$INSTANCE_PROFILE" | grep -q '404 - Not Found'; then
INSTANCE_PROFILE=
fi
if [[ $PROFILE ]]; then
PROFILE_OPT="--profile $PROFILE"
@@ -32,3 +35,13 @@ else
PROFILE="default"
PROFILE_OPT="--profile $PROFILE"
fi
# Set default region by aws config, fall back to us-east-1
REGION_CONFIG=$(aws configure get region)
if [[ $REGION_OPT ]]; then
REGION="$REGION_OPT"
elif [[ $REGION_CONFIG ]]; then
REGION="$REGION_CONFIG"
else
REGION="us-east-1"
fi