How to delete aws iot things and policies?
Asked Answered
F

2

8

Hello i want to delete things and policies created in AWS IoT.

While deleting thing i got this error =>

The action failed because the input is not valid. Cannot delete. Thing Arduino is still attached to one or more principals

While deleting certificate i got this error => The action failed because the resource conflicts with the precondition of the action. Certificate policies must be detached before deletion

While deleting policy i got this error => Failed to delete policy. The policy cannot be deleted as the policy is attached to one or more principals (name=policyyun)

can anyone help? Thanks.

Fimbria answered 15/3, 2016 at 5:44 Comment(1)
If you want to delete policy you should first change the policy version to the default version(version 1), then you can delete it. If you want to delete things or certificates you can delete it easily now without detaching thing. Actually with new console detaching the thing will happen in background. You can find more information here. cheers KeivanAftmost
T
14

I am assuming the thing is created and it is attached to certificate along with the policy. Following is the order to follow while doing cleanup of thing. This will prevent DeleteConflictException due to associations.

  1. DetachPolicy - detach the policy from the certificate
  2. DetachThingPrincipal - detach the certificate from the Thing
  3. UpdateCertificate to set to INACTIVE (or set ForceDelete=true in #4)
  4. DeleteCertificate
  5. DeletePolicy
  6. DeleteThing

Note: You can get the array of principals(cert ARNs) associated with thing using ListThingPrincipals

p.s. The bold texts are APIs in most of the AWS IOT SDK bundles

Taunton answered 28/11, 2017 at 21:48 Comment(1)
Does ForceDelete=true work? In my case (boto3) I need to perform all steps to be able to delete certificate. 1. DetachPolicy. 2. DetachThingPrincipal. 3. UpdateCertificate (to set INACTIVE)Disdain
A
8

You have to detach things, certificates and policies before deleting them.

In the AWS console, select the certificate. Then, on the left panel, in the "Detail" tab, check the thing that you want to delete and "detach" it using the red button.

enter image description here

You will then be able to delete the thing. You have to do the same for policies.

Ammo answered 22/3, 2016 at 19:2 Comment(1)
I'm trying to do this programatically. Is it possible to get the certificate ARN from the Thing, so I can use DetachPrincipalPolicy and DetachThingPrincipal?Salic

© 2022 - 2024 — McMap. All rights reserved.