Skip to content

Commit

Permalink
Fix an issue in the install script where having no region set in the …
Browse files Browse the repository at this point in the history
…CLI errors unhelpfully. (#291)

* Fix an issue where having no region set in the CLI errors unhelpfully.

If you have no region set in the AWS CLI (doable by removing the
'region' line from `.aws/config`) the result of `aws configure list`
will contain the string "<not set>" for the region, meaning the region
is parsed incorrectly in the install script. This leads to an error when
trying to run the installer that is potentially difficult for a
new user to comprehend.

This commit changes the parsing in the install scripts to also check the
configured region against the list of regions using `aws ec2
describe-regions`. If the configured region does not exist in that list,
the installer will prompt the user to configure a valid region.

* Pipe grep output to /dev/null

Co-authored-by: PoeppingT <[email protected]>
  • Loading branch information
PoeppingT and PoeppingT authored Sep 14, 2022
1 parent b798f40 commit b5f3f0c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ if ([string]::IsNullOrWhiteSpace($AWS_REGION))
echo "AWS_REGION not set, check your aws profile or set AWS_DEFAULT_REGION"
Exit 2
}
aws ec2 describe-regions | Select-String -Pattern "$AWS_REGION" | Out-Null
if (-not $?)
{
Write-host "Invalid region $AWS_REGION set, please set a valid region using aws configure"
Exit 2
}

cd ${CURRENT_DIR}
Write-host "Building requirements for SaaS Boost"
Expand Down
5 changes: 5 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ fi
# check for AWS region
if [ -z $AWS_DEFAULT_REGION ]; then
export AWS_REGION=$(aws configure list | grep region | awk '{print $2}')
aws ec2 describe-regions | grep "$AWS_REGION" - > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Invalid region set, please set a valid region using \`aws configure\`"
exit 2
fi
if [ -z $AWS_REGION ]; then
echo "AWS_REGION environment variable not set, check your AWS profile or set AWS_DEFAULT_REGION."
exit 2
Expand Down

0 comments on commit b5f3f0c

Please sign in to comment.