amazon-web-servicesaws-clivpcprivate-subnet

Fetch private subnet through name filter


I am trying to fetch private subnet-ids through aws cli. I have used this command earlier:

aws ec2 describe-subnets --filters Name=vpc-id,Values=abc Name=tag:Name,Values=private --query 'Subnets[*].SubnetId'

But this time I don't want to provide a static value=private, instead I want to find subnets that contain the word private in their name.

Is there a way to use contains or begins with in the filters for aws cli command?

Thanks.


Solution

  • If you want to filter for subnets that contain private in the Name tag, you can use:

    aws ec2 describe-subnets --filters "Name=tag:Name,Values=*private*"
    

    If you want to filter for subnets that start with private in the Name tag, you can use:

    aws ec2 describe-subnets --filters "Name=tag:Name,Values=private*"