-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathawscli.funcs
55 lines (49 loc) · 1.16 KB
/
awscli.funcs
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
#!/bin/bash
# First configure awscli by running "aws configure"
# provide Access Key, Secret Key, Default region & Output format
ec2_qry='Reservations[*].Instances[].{Instance:InstanceId,Name:Tags[?Key==`Name`]|[0].Value,State:State.Name}'
aws_instances() {
region=$1
id=$2
if [ -z $region ]; then
echo "Provide region"
return
fi
if [ ! -z $id ]; then
ec2_qry='Reservations[*].Instances[*]'
fi
aws ec2 describe-instances --region "$region" \
--query $ec2_qry\
--instance-id $id\
--output table
}
aws_search_instance() {
region=$1
name=$2
aws ec2 describe-instances \
--region $region\
--filters "Name=tag:Name,Values=$name"\
--output table\
--query $ec2_qry
}
aws_start_instance() {
region=$1
id=$2
aws ec2 start-instances \
--instance-ids $id\
--region $region
}
aws_stop_instance() {
region=$1
id=$2
aws ec2 stop-instances \
--instance-ids $id\
--region $region
}
aws_terminate_instance() {
region=$1
id=$2
aws ec2 terminate-instances \
--instance-ids $id\
--region $region
}