User Tools

Site Tools


linux:jq

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
linux:jq [20/02/2024 17:01] – created - external edit 127.0.0.1linux:jq [12/02/2025 11:30] (current) – [Extracting multiple values in one pass] andrew
Line 57: Line 57:
 SecretSession== SecretSession==
 </code> </code>
 +
 +
 +====== Extracting multiple values in one pass ======
 +
 +Use a comma to separate multiple fields to extract:-
 +
 +Raw outpput for NAT gateways
 +<code json>
 +$ aws ec2 describe-nat-gateways
 +{
 +    "NatGateways": [
 +        {
 +            "CreateTime": "2024-02-10T14:30:57+00:00",
 +            "NatGatewayAddresses": [
 +                {
 +                    "AllocationId": "eipalloc-abcd1234987658428",
 +                    "NetworkInterfaceId": "eni-dcbaabcd12348765b",
 +                    "PrivateIp": "10.10.10.60",
 +                    "PublicIp": "32.231.232.69",
 +                    "AssociationId": "eipassoc-abcddcba123427a41",
 +                    "IsPrimary": true,
 +                    "Status": "succeeded"
 +                }
 +            ],
 +            "NatGatewayId": "nat-abcddcba123467dea",
 +            "State": "available",
 +            "SubnetId": "subnet-abcddcba12349399f",
 +            "VpcId": "vpc-abcddcba12345b91c",
 +            "Tags": [
 +                {
 +                    "Key": "Name",
 +                    "Value": "poc-nat-public1-eu-west-1a-v2"
 +                }
 +            ],
 +            "ConnectivityType": "public"
 +        }
 +    ]
 +}
 +</code>
 +
 +Code to extract just NAT id, state and Elastic ip in use:-
 +<code bash>
 +$ aws ec2 describe-nat-gateways | jq ".NatGateways | .[] | .NatGatewayId, .State, .NatGatewayAddresses[].NetworkInterfaceId"
 +
 +"nat-abcddcba123467dea"
 +"available"
 +"eni-abcddcba1234f5f0b"
 +
 +</code>
 +
 +
 +
 +
 +
  
  
linux/jq.1708448465.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki