-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaws
37 lines (30 loc) · 1.17 KB
/
aws
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
#! /usr/bin/env bash
### Amazon Web Services
if [[ -f ~/.aws/config ]]; then
#functions
function setawsenv {
export AWS_PROFILE="$1"
aws iam list-account-aliases > /dev/null 2>&1 || aws sso login
export SETENV_NAME=$(aws iam list-account-aliases | jq .AccountAliases[0] | sed -e 's/"//g')
if [[ -z $SETENV_NAME ]] || [[ "$SETENV_NAME" == "null" ]]; then
export SETENV_NAME=$AWS_PROFILE
fi
echo "AWS set to $1"
}
complete -W "$(aws configure list-profiles)" setawsenv
export AWS_REGION="us-east-1"
function setawsregion {
export AWS_REGION="$1"
}
#complete -W "$(aws ec2 describe-regions | jq '.Regions[] | .RegionName' | sed -e 's/"//g')" setawsregion
complete -W "us-east-1 us-west-2" setawsregion
function makesshconfig {
aws ec2 describe-instances | jq '.Reservations[].Instances[] | (.Tags[]|select(.Key=="Name")|.Value), .PrivateIpAddress' | while read HOSTNAME; do read IPADDRESS; echo "Host $HOSTNAME" | sed -e 's/"//g'; echo " HostName $IPADDRESS" | sed -e 's/"//g'; done
}
fi
if which aws &> /dev/null; then
if which aws_completer &> /dev/null; then
complete -C aws_completer aws
fi
fi
export AWS_REGION='us-east-1'