'How do I list WAF objects that do not have any resources using the AWS CLI?

I'd like to list all objects in WAF that do not have resources connected to them using the aws cli in my terminal.

Is there anyway I can do this using the aws wafv2 list-web-acl --name --scope <value> AWS cli command with other perimeters?

Thanks



Solution 1:[1]

Looks like there's no cmd for that so I created a script to have the results placed in a file. Might come handy if needed by anyone on here

#!/bin/bash

#list the web acl objects with their corresponding arn and save it in a file
aws wafv2 list-web-acls --scope REGIONAL | grep "ARN" > output.txt

# Next generate only the ARN nos and save output in a seperate file
awk -F\" '{print $4}' output.txt > input.txt

#Create a file to store ARN numbers together with their resources attached
touch resources.txt

#loop through each line and  generate the resource attached to an ARN object based on its ARN no
while read p; do
  echo $p >> resources.txt && \
  aws wafv2 list-resources-for-web-acl --web-acl-arn $p >> resources.txt && \
  echo ------------------------ >> resources.txt
  #echo -e ' \t ' >> resources.txt
done < input.txt

#remove unwanted files
rm input.txt output.txt

#list webacl objects that do not have resources attached to them
grep -B 3 "\[\]" resources.txt | grep "webacl"

#remove any files left
rm resources.txt

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kofisis