User Tools

Site Tools


virtualization:cloud:aws:jq

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
virtualization:cloud:aws:jq [2021/12/10 12:46] – external edit 127.0.0.1virtualization:cloud:aws:jq [2023/11/02 14:38] (current) – external edit 127.0.0.1
Line 1: Line 1:
- +  Simple introduction [[https://tecadmin.net/linux-jq-command/#:~:text=The%20JQ%20command%20is%20used,data%20from%20a%20JSON%20file|External_Link]] 
-JQ stands for 'json query'\\ +  * Medium introduction [[https://lzone.de/cheat-sheet/jq|External_Link]] 
-  Objects (dictionaries) +  * Excellent/complex examples of jq filters : [[https://github.com/ipspace/docker-examples/tree/d8599f8b4e44b24cc50afafd8a56438ab31bf80b/filter]]
-  * Arrays (lists) +
-  * strings+
  
   jq . # the dots means 'applies for all objects below'   jq . # the dots means 'applies for all objects below'
  
 +For __Docker__:\\
 +networks:
 +  aws ec2 describe-subnets | jq .[] | jq .[].Ipv6CidrBlockAssociationSet | jq .[].Ipv6CidrBlockState    # nested jq (two levels here)
   aws ec2 describe-regions  | jq -r "[[.Regions[].RegionName]]"   aws ec2 describe-regions  | jq -r "[[.Regions[].RegionName]]"
   aws ec2 describe-vpcs | jq -r "[[.Reservations[].Instances[].InstanceId]]"  # extract all instances id (down 3 levels)   aws ec2 describe-vpcs | jq -r "[[.Reservations[].Instances[].InstanceId]]"  # extract all instances id (down 3 levels)
   aws ec2 describe-vpcs | jq -r '.Vpcs | length'   # COUNT number of VPCs   aws ec2 describe-vpcs | jq -r '.Vpcs | length'   # COUNT number of VPCs
   aws ec2 describe-vpcs --region eu-west-1 | jq -r '.Vpcs | length'    # For a DIFFERENT Region   aws ec2 describe-vpcs --region eu-west-1 | jq -r '.Vpcs | length'    # For a DIFFERENT Region
-  +  cat response.json | jq .data | jq -r '.[].relationships.managed_object.data.id' 
 +  cat response.json| jq .data | jq -r '[.[].relationships.managed_object.data.id + " " + .[].attributes.alert_type]'  # two fields 
 +  cat response.json| jq '.data | .[] | .attributes'    # strips 'data' values for all 'attributes' keys 
 +  cat response.json| jq '.data | .[] | .attributes.subobject.dns_scoping' 
 + 
 +PRETTY TABLE FORMAT:\\ 
 + 
 +  aws ec2 describe-instances \ 
 +  --query 'Reservations[*].Instances[*].{Instance:InstanceId,Name:Tags[?Key==`Name`][0].Value,Private:PrivateIpAddress,Public:PublicIpAddress}'
 +  --filters "Name=instance-state-name,Values=running"
 +  --output table 
 + 
 +{{:virtualization:cloud:aws-cli-query.jpeg?900|}} 
 + 
  
 Lists the public IPs (querying the OCI DNS):  Lists the public IPs (querying the OCI DNS): 
Line 36: Line 51:
 \\ \\
   oci network nsg list --region us-phoenix-1 --compartment-id ocid1.compartment.oc1..aaaaaaaax5zpuw6ggeudpiqueidy5xlqentk2ngs7p6445an34mgwlrpbccq | jq -r '.data[] | ."defined-tags"."NetworkSecurity"."groupId" + ": " + .id'   oci network nsg list --region us-phoenix-1 --compartment-id ocid1.compartment.oc1..aaaaaaaax5zpuw6ggeudpiqueidy5xlqentk2ngs7p6445an34mgwlrpbccq | jq -r '.data[] | ."defined-tags"."NetworkSecurity"."groupId" + ": " + .id'
 +
 +\\
 +Formatted output with my own labels [[https://my.ipspace.net/bin/get/DockerNet/Docker%20Networking%20Deep%20Dive.pdf?doccode=DockerNet|External Link]]:\\
 +  .[]|{
 +    Name, Gateway: .IPAM.Config[]|.Gateway,
 +    Endpoints: [
 +      .Containers|to_entries[]|{
 +        Name: .value.Name, IPv4: .value.IPv4Address }
 +    ]
 +  }
 +  
 +  docker network inspect bg0 | jq -f myfilterabove
 +
 +
 +  * ''to_entries'' and ''from_entries'' to convert between objects and key-value pair arrays
 +
 +
virtualization/cloud/aws/jq.1639140374.txt.gz · Last modified: (external edit)