Continuous AWS IAM Security Best Practices
There are some great guides on the internet for AWS Security best practices (both official and unofficial).
However, one of the challenges we saw with those guides is that they tell you what the end goal is,
but they usually leave it up to the user on how to implement it (at scale),
let alone how to continuously monitor those best practices to make sure all your hard work doesn’t go through the window.
In this blog post we will go through the official security IAM best practices, and we'll show how to validate and monitor them using SQL statements with CloudQuery.
Account Setup
You can run all the following commands on a single AWS account. You can also run them on multiple accounts in parallel, using an account that can assume-role into all your other relevant accounts.
CloudQuery Setup
To be able to run the following tutorial you need to install and configure CloudQuery.
Security Best Practices in IAM
In this section, we will share snippets of SQL statements, which you can find in our SQL-based policies.
You can also use this as a reference to create your own policies, which can be customized to your needs and the security policies of your organization.
Lock away your root account
One best practice in AWS is to enable MFA (on your root account) and create an IAM admin user to handle all your day-to-day work immediately after you open an account.
List root accounts that were accessed in the last 30 days:
Also, it is strongly advised not to create any access keys for the root account.
To list root accounts with access keys:
Use groups to assign permissions to IAM
Instead of attaching IAM policies to users it is advised to attach IAM policies to groups and roles, and then to assign the groups and roles to users.
To list accounts with IAM policies attached directly:
Grant least privilege
Creating and reviewing IAM policies with least privilege in mind is a big topic on its own.
We will cover this in a follow-up post!
Configure a strong password policy for your users
If you allow users to change their own password, then creating a password policy is highly recommended.
This snippet is taken from AWS CIS benchmark. It provides a good example of a strong password policy and offers a way to check that it is enabled in all accounts. For a complete guide to running all CIS AWS checks - including the updated v3.0 controls, multi-account compliance views, and exception management - see AWS CIS Benchmark in 2026: Automated Compliance with SQL-Based Policies.
Enable MFA
AWS recommends that MFA be enabled for the root account, as well as any other privileged IAM users.
To list all accounts with MFA disabled:
For example, if you only want to alert on specific accounts, you can add a list of accounts to the SQL statements.
Or you can go even further by joining on the permissions table and alerting on accounts with specific permissions that do not have MFA enabled.
Rotate access keys
To list all access keys that weren’t rotated in the last 90 days you can run the following:
Remove unnecessary credentials
To list all IAM access keys that haven’t been used for more than 90 days:
CloudQuery Policies
We implemented many compliance SQL queries that you can check out here.
These SQL queries will create an aws_policy_results table that you can then query.
Stay tuned for more blogs on cloud security, compliance and other cool stuff!
Want to see CloudQuery in action? Schedule a demo with our team or check out the platform documentation to learn more.
Want help getting started? Join the CloudQuery community to connect with other users and experts, or message our team directly here if you have any questions.
Try CloudQuery yourself
Self-hosted, open source, and free to start. Or schedule a demo to see the managed version.



