-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathami.sh
25 lines (21 loc) · 1001 Bytes
/
ami.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/bash
########################################################################
### LOOKUP ##################################################
########################################################################
function findAmi {
if [ -z "$1" ]; then
echo "must supply filters in first parameter (ie Name=name,Values=amzn*) etc."
return 1
fi
local aid="$(getAccountId)"
local owners="$aid"
if [ ! -z "$2" ]; then
local owners="$2"
fi
#local owners="137112412989"
#echo "aws --profile $PROFILE --region $REGION ec2 describe-images --owners $owners --filters $1 --query 'sort_by(Images, &CreationDate)[0].ImageId' --output text 2>/dev/null"
local foo=$(aws --profile $PROFILE --region $REGION ec2 describe-images --owners $owners --filters $1 --query 'sort_by(Images, &CreationDate)[0].ImageId' --output text 2>/dev/null)
if [ $? -ne 0 ]; then return 1; fi
if [ -z "$foo" ]; then return 1; fi
echo "$foo"
}