The listing functions output lines of tokens. The first token is the resource identifier. Piping that output into functions for that resource type results in the resource IDs only being used.
$ instances
i-03dfa28fc8235df7b t3.nano running prometheus 2019-12-31T14:10:45.000Z ap-southeast-2a vpc-9def06f8
i-0fd7a4c81051f2718 t3.nano running huginn 2019-12-31T14:10:44.000Z ap-southeast-2a vpc-9def06f8
i-0abcd6e9c302f35bb t3.nano running rails-demo 2019-12-31T14:10:47.000Z ap-southeast-2b vpc-9def06f8
$ instances | grep rails-demo | instance-asg | asg-capacity
rails-demo-AutoScalingGroup-14SBR6O3W1FBL 0 1 2
$ instances | grep rails-demo | instance-asg | asg-
asg-capacity asg-launch-configuration asg-processes_suspended asg-stack
asg-desired-size-set asg-max-size-set asg-resume asg-suspend
asg-instances asg-min-size-set asg-scaling-activities
$ instances | grep rails-demo | instance-asg | asg-desired-size-set 2
$ instances | grep rails-demo | instance-asg | asg-capacity
rails-demo-AutoScalingGroup-14SBR6O3W1FBL 0 2 2The problem I run into is that it just feels like so much typing to me. I have to read documentation. All the attributes HaveReallyLongNamesThatContainCapitalLetters. By the time I've made my beta version of the command I want to run, I feel like I need to open a text editor to finish it. Maybe add some error checking. Some comments too. Maybe a unit test or three. And now I have an entire project and all I wanted to do was add a line of text to the end of a file.
Part of the problem on my part is my own ignorance of the APIs and what commands are available to me. But it all seems too verbose to use practically. The Powershell language seems very good for what you would write a shell script to do, but for interactive commands, I have a hard time believing that people use it. It's just so verbose.
The result is you have a simple set of commands that don't require you to type hundreds of characters.
instances() {
local instance_ids=$(__bma_read_inputs)
local filters=$(__bma_read_filters $@)
aws ec2 describe-instances \
$([[ -n ${instance_ids} ]] && echo --instance-ids ${instance_ids}) \
--query "
Reservations[].Instances[][
InstanceId,
InstanceType,
State.Name,
[Tags[?Key=='Name'].Value][0][0],
LaunchTime,
Placement.AvailabilityZone,
VpcId
]" \
--output text |
grep -E -- "$filters" |
LC_ALL=C sort -b -k 6 |
column -s$'\t' -t
}