Search code examples
amazon-web-servicesaws-cliaws-iot

AWS CLI returns "null" when querying a IoT device shadow


I have an AWS IoT Thing with a device shadow. I can query the device shadow using:

aws iot-data get-thing-shadow --thing-name 1234567 --output=json shadow.json

The contents of shadow.json file looks something like this:

{
  "state": {
    "desired": {
      "welcome": "aws-iot",
      "attribute1": 0
    },
    "reported": {
      "welcome": "aws-iot"
    },
    "delta": {
      "attribute1": 0
    }
  },
  "metadata": {
    "desired": {
      "welcome": {
        "timestamp": 1676620139
      },
      "attribute1": {
        "timestamp": 1676620250
      }
    },
    "reported": {
      "welcome": {
        "timestamp": 1676620139
      }
    }
  },
  "version": 2,
  "timestamp": 1676623598
}

But when I try to use the --query parameter to filter the results, the return is just null:

aws iot-data get-thing-shadow --thing-name 1234567 --output=json  --query 'state.desired'  shadow.json
null

If I test my filtering query on https://jmespath.org/, the filter seems to work just fine and produces:

{
  "welcome": "aws-iot",
  "attribute1": 0
}

What am I doing wrong?

AWS CLI version: 2.10.0


Solution

  • I was also curious on this and opened an issue. The reason you can not query looks because the GetThingShadow API does not return the shadow doc as data.

    I think what you're describing is the expected behavior, as the GetThingShadow API only returns an HTTP 200 response if successful.