-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbashrc.work
More file actions
46 lines (39 loc) · 1.64 KB
/
bashrc.work
File metadata and controls
46 lines (39 loc) · 1.64 KB
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
# vim:ft=sh
# work specific shell configurations
CDPATH=".:$HOME/Repos/"
GAPPS_DIRSYNC_SSH_TUNNEL="1389:localhost:389 ldap.glencoesoftware.com"
if [ -e ~/.ec2/bashrc.aws ]; then
. ~/.ec2/bashrc.aws
fi
alias doaws="aws --endpoint https://nyc3.digitialoceanspaces.com"
function ssh-eice(){
local -r query="${1}"
local -r region_in="${2}"
declare -a all_regions
if [ -z $region_in ]; then
all_regions=($(aws ec2 describe-regions --query "Regions[].RegionName" --output json | jq -r '.[]'))
else
all_regions+=("$region_in")
fi
for region in "${all_regions[@]}"; do
echo "looking in ${region} for ${query}..."
instance_id=$(aws ec2 describe-instances --region="${region}" --filter "Name=tag:Name,Values=${query}" \
'Name=instance-state-name,Values=running' \
--query 'Reservations[].Instances[].InstanceId' \
--output text)
[ -n "${instance_id}" ] && break
done
if [ -z "${instance_id}" ]; then
echo "EC2 instance not found."
elif [ $(echo "${instance_id}" | wc -w) -gt 1 ]; then
echo "Multiple EC2 instances found matching your query. Narrow down your query."
else
echo "---------------------------------------------------------------------------"
echo "--- Logging into: Instance-Id: ${instance_id} -- Region: ${region}"
echo "---------------------------------------------------------------------------"
aws ec2-instance-connect ssh --region="${region}" \
--os-user ubuntu \
--instance-id="${instance_id}" \
--connection-type eice
fi
}