-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssm.sh
executable file
·56 lines (45 loc) · 998 Bytes
/
ssm.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
48
49
50
51
52
53
54
55
56
#!/bin/bash -e
SDIR=$(dirname $0)
CONF="conf.yaml"
if [ ! -f $SDIR/$CONF ]; then
CONF=$SDIR/ssm/$CONF
fi
function haveYq() {
which yq > /dev/null
if [ "$?" == "1" ]; then
echo "Instal yq first. ==> https://mikefarah.gitbook.io/yq"
fi
}
function _print_ec2() {
echo "Select EC2"
len=$(yq r $CONF --length ec2)
for (( i=0; i<$len; i++ )); do
echo $i: $(yq r $CONF -j "ec2.[$i]" | jq .'name')
done
}
function _print_profile() {
echo "Select profile"
len=$(yq r $CONF --length profile)
for (( i=0; i<$len; i++ )); do
echo $i: $(yq r $CONF -j "profile.[$i]" | jq .'name')
done
}
function print(){
if [ "$1" == "ec2" ]; then
_print_ec2
fi
if [ "$1" == "profile" ]; then
_print_profile
fi
}
function main() {
haveYq
print "ec2"
read ec2_idx
print "profile"
read prof_idx
inst=$(yq r $CONF ec2.[$ec2_idx].'id')
prof=$(yq r $CONF profile.[$prof_idx].'name')
aws ssm start-session --target $inst --profile $prof
}
main