I need to get the Internet Gateways which are NOT attached to any of the vpc networks in aws.
Here, this below command:
igws=(aws ec2 describe-internet-gateways --query 'InternetGateways[*]' --region $REGION
echo $igws
This produces the output as below:
- for an attached
internet gatewaytheAttachmentsblock is not empty
[
{
"Attachments": [
{
"State": "available",
"VpcId": "vpc-2e83a147"
}
],
"InternetGatewayId": "igw-5a61f333",
"OwnerId": "<some-id>",
"Tags": []
}
]
- for an detached
internet gatewaytheAttachmentsblock is empty
[
{
"Attachments": [],
"InternetGatewayId": "igw-0c8abdc3cb147c04d",
"OwnerId": "<some-id>",
"Tags": [
{
"Key": "Name",
"Value": "VPNTEST"
}
]
}
]
How can I check if the Attachment value is empty or not?
I used the below command but it is not working as it doesnt capture the detached ones:
if [ -z "$igws.Attachments[]" ]; then
do
echo "empty"
else
echo "not empty"
fi
can someone help me?