Skip to content

Commit

Permalink
Added helper function for AWS
Browse files Browse the repository at this point in the history
  • Loading branch information
akash0x53 committed Aug 13, 2020
1 parent 0471e32 commit 6019416
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
44 changes: 44 additions & 0 deletions awscli.funcs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

# First configure awscli by running "aws configure"
# provide Access Key, Secret Key, Default region & Output format

ec2_qry='Reservations[*].Instances[*].{Instance:InstanceId,AZ:Placement.AvailabilityZone,Name:Tags[?Key==`Name`]|[0].Value,State:State.Name}'
aws_instances() {
region=$1
id=$2
if [ ! -z $id ]; then
ec2_qry='Reservations[*].Instances[*]'
fi
aws ec2 describe-instances --region "$region" \
--query $ec2_qry\
--instance-id $id\
--output table
}

search_instance() {
region=$1
name=$2
aws ec2 describe-instances \
--region $region\
--filters "Name=tag:Name,Values=$name"\
--output table\
--query $ec2_qry
}

start_instance() {
region=$1
id=$2
aws ec2 start-instances \
--instance-ids $id\
--region $region
}

stop_instance() {
region=$1
id=$2
aws ec2 stop-instances \
--instance-ids $id\
--region $region
}

1 change: 1 addition & 0 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ if [ -f "$HOME/.bashrc" ]; then
echo "NOTE: .bashrc file locked"
else
echo "source $PWD/bashrc.funcs" >> $HOME/.bashrc
echo "source $PWD/awscli.funcs" >> $HOME/.bashrc
echo "source $PWD/bashrc" >> $HOME/.bashrc
chmod -w "$HOME/.bashrc"
fi
Expand Down

0 comments on commit 6019416

Please sign in to comment.