Skip to content

Instantly share code, notes, and snippets.

@omerap12
Last active February 21, 2024 09:33
Show Gist options
  • Save omerap12/1e7fb8bdc14b8fa3af2cab737c917d37 to your computer and use it in GitHub Desktop.
Save omerap12/1e7fb8bdc14b8fa3af2cab737c917d37 to your computer and use it in GitHub Desktop.
Remove AWS IAM Role
role_name=$1
aws iam list-instance-profiles-for-role --role-name $role_name | jq -r '.InstanceProfiles[].InstanceProfileName' | xargs -I {} aws iam remove-role-from-instance-profile --instance-profile-name {} --role-name $role_name
aws iam list-role-policies --role-name $role_name | jq -r '.PolicyNames[]' | xargs -I {} aws iam delete-role-policy --role-name $role_name --policy-name {}
aws iam list-attached-role-policies --role-name $role_name | jq -r '.AttachedPolicies[].PolicyArn' | xargs -I {} aws iam detach-role-policy --role-name $role_name --policy-arn {}
aws iam delete-role --role-name $role_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment