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 [2022/09/06 18:47] – 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:
-Excellent examples of jq filters : [[https://github.com/ipspace/docker-examples/tree/d8599f8b4e44b24cc50afafd8a56438ab31bf80b/filter]]+  * Simple introduction [[https://tecadmin.net/linux-jq-command/#:~:text=The%20JQ%20command%20is%20used,data%20from%20a%20JSON%20file|External_Link]] 
 +  * Medium introduction [[https://lzone.de/cheat-sheet/jq|External_Link]] 
 +  * Excellent/complex examples of jq filters : [[https://github.com/ipspace/docker-examples/tree/d8599f8b4e44b24cc50afafd8a56438ab31bf80b/filter]]
  
   jq . # the dots means 'applies for all objects below'   jq . # the dots means 'applies for all objects below'
Line 5: Line 7:
 For __Docker__:\\ For __Docker__:\\
 networks: networks:
-  docker inspect <network-id>| jq .[].Containers    # containers attached to a certain network  +  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]]:\\ Formatted output with my own labels [[https://my.ipspace.net/bin/get/DockerNet/Docker%20Networking%20Deep%20Dive.pdf?doccode=DockerNet|External Link]]:\\
virtualization/cloud/aws/jq.1662490020.txt.gz · Last modified: (external edit)