-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions-aws.sh
47 lines (36 loc) · 1.1 KB
/
functions-aws.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
function ls-ec2-instances() {
[[ -n "$AWS_PROFILE" ]] && echo "AWS_PROFILE=$AWS_PROFILE" && echo ""
aws ec2 describe-instances --output json | jq -r '.Reservations[].Instances[] | [.InstanceId, .State.Name,(.Tags[]?|select(.Key=="Name")|.Value) ] |@tsv '
}
function awsprof() {
AWS_CONFIGFILE=$HOME/.aws/config
profiles=($(cat $AWS_CONFIGFILE |perl -ne '(s/\[profile (.*?)\]/$1/ && print ) if /\[profile/'))
FILTER=${1:-""}
# present menu for user to choose which branch to checkout
PS3="Please choose your aws profile from your $AWS_CONFIGFILE: "
echo ""
COLUMNS=10
select opt in "${profiles[@]}"
do
case $opt in
*)
echo "switching to profile $opt ..."
export AWS_PROFILE=$opt
break
;;
esac
done
}
function aws-export-env() {
local tmpEnv=$(mktemp)
aws configure export-credentials --format=env > $tmpEnv
source $tmpEnv
rm $tmpEnv
}
function aws-unset-env() {
unset AWS_CREDENTIAL_EXPIRATION
unset AWS_SESSION_TOKEN
unset AWS_SECRET_ACCESS_KEY
unset AWS_ACCESS_KEY_ID
}