From a73bb314cc562318bfa9d7a0c95004bfefd98e80 Mon Sep 17 00:00:00 2001 From: dcarrillo Date: Sat, 22 Feb 2020 19:41:14 +0100 Subject: [PATCH] [aws] Fix switch_aws_profile when dealing with AWS_DEFAULT_REGION --- modules/aws/functions/aws-info | 2 +- modules/aws/init.zsh | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/aws/functions/aws-info b/modules/aws/functions/aws-info index 546b445..1035548 100644 --- a/modules/aws/functions/aws-info +++ b/modules/aws/functions/aws-info @@ -13,7 +13,7 @@ typeset -gA aws_info if (( ${+AWS_PROFILE} )); then - if (( ${+AWS_DEFAULT_REGION+1} )) && [[ ${_aws_region} = "true" ]]; then + if (( ${+AWS_DEFAULT_REGION} )) && [[ ${_aws_region} = "true" ]]; then AWS_REGION=$(cut -d "-" -f 1 <<<$AWS_DEFAULT_REGION | cut -b 1)$(cut -d "-" -f 2 <<<$AWS_DEFAULT_REGION | cut -b 1)$(cut -d "-" -f 3 <<<$AWS_DEFAULT_REGION | cut -b 1) AWS_REGION_PROMPT=" $AWS_REGION" fi diff --git a/modules/aws/init.zsh b/modules/aws/init.zsh index b1e5b91..dc2cc26 100644 --- a/modules/aws/init.zsh +++ b/modules/aws/init.zsh @@ -136,9 +136,15 @@ function ssh_aws_any { function aws_switch_profile { echo "Activating profile $1..." - export AWS_PROFILE=$1 + local region + export AWS_PROFILE=$1 if [[ -f ~/.aws/credentials ]]; then #&& (( ! ${+AWS_DEFAULT_REGION} )) - export AWS_DEFAULT_REGION=$(aws configure get region) + region=$(aws configure get region) + if [[ ! -z $region ]]; then + export AWS_DEFAULT_REGION=$region + else + unset AWS_DEFAULT_REGION + fi fi }