Cannot be used with Windows AWS CLI under Cygwin (fix included)
The easiest way to get the AWS CLI under Cygwin is to simply install the Windows version, and then make sure that the Cygwin PATH picks up the new directory or the automatically-adjusted Windows PATH. However, the Windows AWS CLI uses <CR><LF> line terminators in its text output, which breaks most shell scripts, including delete_vpc.sh.
Under Cygwin, this shows up as an early failure in this bit of code:
# Check VPC status, available or not
state=$(aws ec2 describe-vpcs \
--vpc-ids "${VPC_ID}" \
--query 'Vpcs[].State' \
--region "${AWS_REGION}" \
--output text)
if [ "${state}" != 'available' ]; then
echo "The VPC of ${VPC_ID} is ${state}, NOT available now!"
exit 1
fi
The "state" variable will consist of available\r and fail the comparison test. (Trying to print it to the screen with echo leads to amusing results.)
An easy workaround is to have the shell script run a function for 'aws' calls instead. Just after the test for an installed AWS CLI, I added this:
if [[ "$(uname -s)" == CYGWIN* ]]; then
aws() {
command aws "$@" | tr -d '\r'
}
fi
and the rest of the shell script required no changes.
Thank you very much for such a useful tool!