Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions alias
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,13 @@ revoke-my-ip-all =
!f() {
aws revoke-my-ip ${1} all all
}; f

get-vpc-id-by-name =
!f() {
aws ec2 describe-vpcs --filter "Name=tag:Name,Values=${1}" --query 'Vpcs[*].{id:VpcId}' --output text
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should be able to simplify your --query by just making it: --query 'Vpcs[].[VpcId] and should be the same result

Copy link

@virgilwashere virgilwashere Nov 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kyleknap the alias as submitted with curly braces, seems correct.

$ aws ec2 describe-vpcs --filter "Name=tag:Name,Values=vpc_name" --query 'Vpcs[].[id:VpcId]' --output text

Bad value for --query Vpcs[].[id:VpcId]: Expecting: comma, got: colon: Parse error at column 10, token ":" (COLON), for expression:
"Vpcs[].[id:VpcId]"
           ^
$ aws ec2 describe-vpcs --filter "Name=tag:Name,Values=vpc_name" --query 'Vpcs[].{id:VpcId}' --output text
vpc-01234567890123456

However, @fdavis you can also do this:

Suggested change
aws ec2 describe-vpcs --filter "Name=tag:Name,Values=${1}" --query 'Vpcs[*].{id:VpcId}' --output text
aws ec2 describe-vpcs --query "Vpcs[?Tags[?Key==\`Name\`]|[?Value==\`${1:?Need a VPC Name}\`]].VpcId" --output text

}; f

get-vpc-name-by-id =
!f() {
aws ec2 describe-vpcs --filter "Name=vpc-id,Values=${1}" --query 'Vpcs[*].Tags[].Value' --output text
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like we are including values of all tags. I think we should only be including the Name tag in what is returned.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also recommend to include only the tag Name. +1 to include these 2 in the aliases.

Copy link

@virgilwashere virgilwashere Nov 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
aws ec2 describe-vpcs --filter "Name=vpc-id,Values=${1}" --query 'Vpcs[*].Tags[].Value' --output text
aws ec2 describe-vpcs --vpc-ids "${1:?Need a VPCId}" --query 'Vpcs[].Tags[?Key==`Name`].Value' --output text

}; f