Conversation
|
How about adding a get-vpc-name-by-id like this? aws ec2 describe-vpcs --filter "Name=vpc-id,Values=${1}" --query 'Vpcs[*].Tags[].Value' --output text |
|
Added, I like that it matches a partial vpc-id as well |
kyleknap
left a comment
There was a problem hiding this comment.
Thanks for the PR! I like both aliases. I just had a feedback comment for both of the aliases.
|
|
||
| get-vpc-id-by-name = | ||
| !f() { | ||
| aws ec2 describe-vpcs --filter "Name=tag:Name,Values=${1}" --query 'Vpcs[*].{id:VpcId}' --output text |
There was a problem hiding this comment.
I think you should be able to simplify your --query by just making it: --query 'Vpcs[].[VpcId] and should be the same result
There was a problem hiding this comment.
@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-01234567890123456However, @fdavis you can also do this:
| 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 |
|
|
||
| get-vpc-name-by-id = | ||
| !f() { | ||
| aws ec2 describe-vpcs --filter "Name=vpc-id,Values=${1}" --query 'Vpcs[*].Tags[].Value' --output text |
There was a problem hiding this comment.
This looks like we are including values of all tags. I think we should only be including the Name tag in what is returned.
There was a problem hiding this comment.
I would also recommend to include only the tag Name. +1 to include these 2 in the aliases.
|
|
||
| get-vpc-name-by-id = | ||
| !f() { | ||
| aws ec2 describe-vpcs --filter "Name=vpc-id,Values=${1}" --query 'Vpcs[*].Tags[].Value' --output text |
There was a problem hiding this comment.
| 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 |
we have a lot of accounts and vpcs so its helpful to be able to grab a vpc-id for other configs/placement