Skip to content

Commit

Permalink
Merge pull request #792 from ministryofjustice/ag--fix-delete-app-whe…
Browse files Browse the repository at this point in the history
…n-no-role

Fix delete app/user when IAM role doesn't exist
  • Loading branch information
xoen authored Dec 18, 2019
2 parents 8aa86d6 + 0e0049b commit 5589897
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions controlpanel/api/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging

import boto3
import botocore
from django.conf import settings


Expand Down Expand Up @@ -181,9 +182,11 @@ def delete_role(name):
try:
role = boto3.resource('iam').Role(name)
role.load()
except role.meta.client.exceptions.NoSuchEntityException:
log.warning(f'Skipping delete of Role {name}: Does not exist')
return
except botocore.exceptions.ClientError as e:
if e.response["Error"]["Code"] == "NoSuchEntity":
log.warning(f'Skipping delete of Role {name}: Does not exist')
return
raise e

for policy in role.attached_policies.all():
role.detach_policy(PolicyArn=policy.arn)
Expand Down

0 comments on commit 5589897

Please sign in to comment.