Mr. Annonymous
Mr. Annonymous

Reputation: 87

Cannot delete entity, must remove tokens from principal first

while trying to delete aws user from AWS Java SDK. i am getting following error:

Cannot delete entity, must remove tokens from principal first.

the relevant code snippet is:

DeleteUserRequest deleteUserRequest = DeleteUserRequest.builder().userName(userName).build();
iam.deleteUser(deleteUserRequest);

Upvotes: 3

Views: 4374

Answers (1)

Jonathan Petitcolas
Jonathan Petitcolas

Reputation: 4584

I faced the same issue with Terraform. The user had some access tokens and MFA devices configured on their account. They have created it manually, hence, Terraform didn't know about that. So, it was not able to delete the user due to the exact same error.

Deleting the MFA tokens and the manually generated access tokens fixed the issue.

Perhaps can you automate it with Java?

Upvotes: 9

Related Questions