0
[
  [
    {
      "Instance": "i-024567574b4cb",
      "BlockDeviceMappings": [
        {
          "DeviceName": "/dev/xvda",
          "DeleteOnTermination": true
        },
        {
          "DeviceName": "/dev/xcda",
          "DeleteOnTermination": false
        }
      ]
    }
  ],
  [
    {
      "Instance": "i-05ff5346656a1a",
      "BlockDeviceMappings": [
        {
          "DeviceName": "/dev/xvda",
          "DeleteOnTermination": true
        },
        {
          "DeviceName": "/dev/xcda",
          "DeleteOnTermination": false
        }
      ]
    },
    {
      "Instance": "i-00764y45ybe7dc",
      "BlockDeviceMappings": [
        {
          "DeviceName": "/dev/xvda",
          "DeleteOnTermination": true
        }
      ]
    }
  ]
]

How to get "instance id" and Device Name using shell script or jq or python for the instances where delete on termination is false?

expected

i-024567574b4cb, /dev/xcda
i-05ff5346656a1a, /dev/xcda

  • If you have trouble using the linked duplicate's answer, [edit] to show how you tried to apply that answer and what you got instead of the desired output, and @-notify me so I can review for reopening if this asks a new and distinctive (narrow, specific) question as-edited. – Charles Duffy Mar 16 '21 at 16:27
  • ...re: "parent and inner" -- we do also already have questions showing that, but quicker than finding one to update the duplicate list is just to specify: once you've navigated to the parent, you can do something like `. as $parent | .BlockDeviceMappings[] | select(.DeleteOnTermination==false) | [$parent.Instance, .DeviceName]` – Charles Duffy Mar 16 '21 at 17:04
  • ...added [jq: How do I print a parent value of an object when I am already deep into the object?](https://stackoverflow.com/questions/38689645/jq-how-do-i-print-a-parent-value-of-an-object-when-i-am-already-deep-into-the) to the duplicate list, towards that end. – Charles Duffy Mar 16 '21 at 17:06

0 Answers0