Detaching IAM policies and removing IAM role in AWS CLI

roles=("RoleA" "RoleB" "RoleC")for role in ${roles[@]} ;
do
echo "Role $role"
role_attached_policies=$(aws iam list-attached-role-policies --role-name $role --query 'AttachedPolicies[*].PolicyArn' --output text)
for policy_arn in $role_attached_policies ;
do
aws iam detach-role-policy --role-name $role --policy-arn $policy_arn
done
role_inline_policies=$(aws iam list-role-policies --role-name $role --query 'PolicyNames' --output text)
for policy_name in $role_inline_policies ;
do
aws iam delete-role-policy --role-name $role --policy-name $policy_name
done

aws iam delete-role --role-name $role
done

--

--

--

Senior Cloud Engineer @ VanMoof. JVM (Java/Kotlin/Groovy) developer. Founded Thalatta, a SaaS startup https://twitter.com/alkoclick

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Twelve Factor App for Microservices

Sorting Techniques.

How to Reset Samsung Galaxy J5 ⑥ SM-J510FN

Reset Samsung Galaxy

Common App Development mistakes you should avoid at all costs

mobile app development company in london

Deploy Laravel 9 on Google Cloud Run + Sql + MySql + Cloud Build

Zero to Hero in Python in 30 days: Day 14: Lists

Implementing a retro game over behavior in Unity

The DevOps Engineer Craze — Who You Should Really Hire

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alexander Papageorgiou

Alexander Papageorgiou

Senior Cloud Engineer @ VanMoof. JVM (Java/Kotlin/Groovy) developer. Founded Thalatta, a SaaS startup https://twitter.com/alkoclick

More from Medium

AWS Load Balancer

CloudWatch Subscription Filters

Understanding Cloudwatch Metrics and Alarms — Monitoring Cloud Services

Distributed “MinIO” Object storage setup on AWS infra