-
Notifications
You must be signed in to change notification settings - Fork 0
/
awsswitch.sh
32 lines (28 loc) · 925 Bytes
/
awsswitch.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
# This is meant to be called with 'source' since it sets environment variable.
# Add:
# alias awsswitch="source <PATH OF AWSSWITCH>/awsswitch.sh"
# to your .bash_profile to make your life simpler
AWS_INFO="amplify/.config/local-aws-info.json"
DIR=$(pwd)
# Find the right top-level directory
while [ -n "$DIR" ]; do
AWS_INFO_PATH="${DIR}/amplify/.config/local-aws-info.json"
if [ -f "$AWS_INFO_PATH" ]; then
break
fi
DIR=$(echo "${DIR}" | sed 's=/[^/]*$==g')
done
if [ -z "$AWS_PROFILE" ]; then
export AWS_PROFILE=administrator
echo "Switched to administrator AWS profile"
if [ -f "$AWS_INFO_PATH" ]; then
sed -i '' 's/"profileName": ".*"/"profileName": "administrator"/g' "$AWS_INFO_PATH"
fi
else
unset AWS_PROFILE
echo "Switched to default AWS profile"
if [ -f "$AWS_INFO_PATH" ]; then
sed -i '' 's/"profileName": ".*"/"profileName": "default"/g' "$AWS_INFO_PATH"
fi
fi