Last active
October 12, 2018 05:02
-
-
Save alexsapran/0945ebabfb6070a018789d4ac6774215 to your computer and use it in GitHub Desktop.
AWS CLI bash wrapper dot file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_warning(){ | |
echo -e "\e[31m${@}\e[0m" | |
} | |
_info(){ | |
echo -e $@ | |
} | |
_success(){ | |
echo -e "\e[32m${@}\e[0m" | |
} | |
aws_s3_buckets(){ | |
aws s3api list-buckets --query 'Buckets[].Name' --output table | |
} | |
aws_s3_list() { | |
if [ -z "$1" ]; then | |
_warning "Missing the bucket name"; | |
_info "usage: aws_s3_list <bucket_name>" | |
_info "to get bucket names run aws_s3_buckets" | |
return ; | |
fi | |
aws s3api list-objects --bucket $1 --query 'Contents[].{Key: Key, Size: Size, LastModified: LastModified}' --output table | |
} | |
aws_instance(){ | |
aws ec2 describe-instances \ | |
--no-paginate \ | |
--query "Reservations[].Instances[] \ | |
[\ | |
[Tags[?Key=='Name'].Value][0][0],\ | |
InstanceId,\ | |
PublicIpAddress || PrivateIpAddress,\ | |
ImageId,\ | |
InstanceType,\ | |
State.Name,\ | |
Placement.AvailabilityZone, \ | |
[Tags[?Key=='Cluster'].Value][0][0] \ | |
]" --output table | |
} | |
aws_instance_details(){ | |
if [ -z "$1" ]; then | |
_warning "Missing Instance Id please run aws_instance to get the id"; | |
_info "You can pass more ids as <id> <id>" | |
return ; | |
fi | |
aws ec2 describe-instances \ | |
--output table \ | |
--instance-ids $@ | |
} | |
aws_instance_status(){ | |
if [ -z "$1" ]; then | |
_warning "Missing Instance Id please run aws_instance to get the id"; | |
_info "You can pass more ids as <id> <id>" | |
return ; | |
fi | |
aws ec2 describe-instances \ | |
--output table \ | |
--query "Reservations[].Instances[] \ | |
[\ | |
[Tags[?Key=='Name'].Value][0][0],\ | |
InstanceId,\ | |
PublicIpAddress || PrivateIpAddress,\ | |
State.Name,\ | |
[Tags[?Key=='Cluster'].Value][0][0] \ | |
]" --output table \ | |
--instance-ids $@ | |
} | |
aws_rds(){ | |
aws rds describe-db-instances \ | |
--no-paginate \ | |
--query "DBInstances[] \ | |
[ \ | |
DBInstanceIdentifier,\ | |
Endpoint.Address, \ | |
DBInstanceClass, \ | |
DBInstanceStatus, \ | |
SubnetAvailabilityZone.Name, \ | |
DBInstanceArn \ | |
]" --output table | |
} | |
aws_sqs(){ | |
aws sqs list-queues \ | |
--no-paginate \ | |
--output table | |
} | |
aws_asg() { | |
aws autoscaling describe-auto-scaling-groups \ | |
--no-paginate \ | |
--query "AutoScalingGroups[] \ | |
[ \ | |
AutoScalingGroupName,\ | |
DesiredCapacity, \ | |
MaxSize, \ | |
MinSize, \ | |
join(' ', AvailabilityZones), \ | |
join(' ', Instances[].InstanceId), \ | |
LaunchConfigurationName | |
]" \ | |
--output table | |
} | |
aws_elb() { | |
if [ ! -z "$1" ]; then | |
aws elb describe-load-balancers \ | |
--no-paginate \ | |
--query "LoadBalancerDescriptions[]" \ | |
--output table \ | |
--load-balancer-names $@ | |
else | |
aws elb describe-load-balancers \ | |
--no-paginate \ | |
--query "LoadBalancerDescriptions[] \ | |
[ \ | |
LoadBalancerName,\ | |
join(' ', AvailabilityZones), \ | |
join(' ', Instances[].InstanceId)\ | |
]" \ | |
--output table \ | |
--load-balancer-names $@ | |
fi | |
} | |
aws_elb_tags() { | |
if [ -z "$1" ]; then | |
_warning "Missing loadbalancer name run aws_elb to get the names"; | |
return -1; | |
fi | |
aws elb describe-tags \ | |
--query "TagDescriptions[]" \ | |
--output table \ | |
--load-balancer-name $1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment