aws-greengrass / aws-greengrass-shadow-manager

A GreengrassV2 Component that provides offline device shadow documents and optional synchronization to the IoT device shadow service.
Apache License 2.0
9 stars 5 forks source link

(shadowmanager): Local shadows end up duplicated after clearing and repopulating. #128

Closed cris-b closed 1 year ago

cris-b commented 1 year ago

Describe the bug We occasionally have need to 'reset' all the shadows on a device. We do this by first clearing the shadow and then repopulating it. This works fine on the cloud side, but the local shadow ends up just having the contents of the old shadow plus the new one.

To Reproduce

e.g. original contents:

{ state: { desired: { uuid1: "bla" uuid2: "foo" }, reported: { uuid1: "bla" uuid2: "foo" } }

we then clear the shadow by doing an update like:

{ state: null }

(I've a feeling this is probably not quite right but not sure it should succeed and then error later).

we then set the new state with an update like:

{ state: { desired: { uuid3: "zing" uuid4: "zang" } }

and what we get back when we interrogate the local shadow is:

{ state: { desired: { uuid1: "bla" uuid2: "foo" uuid3: "zing" uuid4: "zang" }. reported: { uuid1: "bla" uuid2: "foo" } }

Expected behavior I would expect the local shadow to mirror the cloud shadow.

Actual behavior Local shadow contains all the old data plus the new data

Environment

saranyailla commented 1 year ago

Hi Cris-b, thanks for using Greengrass shadow manager component. In order to reset the shadow locally, please pass null/None values for both reported and desired states in the payload for the UpdateThingShadowRequest

For eg: If you're using AWS IoT Python SDK, you can set the payload as follows

{"state": {"reported": None, "desired": None}}

and this should set the state to empty when you get the shadow document for the thing "state": {}.

Please feel free to open the issue if you see something different.