Sub topic 14
Checking your baseline with the console and CLI
This chapter turns the earlier setup work into a repeatable check. You will confirm four things: the root user has MFA, the root user has no access keys, your daily identity is not root, and a budget with an alert exists. You can do this in the console and with the AWS CLI.
This chapter assumes you have already done the following:
- Created the account.
- Enabled root MFA.
- Created an administrative identity.
- Created a budget.
- Installed and configured the AWS CLI with the administrative identity, not root.
Why verify instead of trusting your memory
Setup steps fail quietly. An MFA enrollment can be abandoned halfway. An access key created "just to test" gets forgotten. A budget notification can point to a mistyped email address. A verification pass catches these problems. Run it once after setup, and again after any change to the account.
The checks fall into two groups.
- Identity checks answer "who am I, and what can the root user do?"
- Cost checks answer "will I hear about a spending surprise?"
Check 1: confirm who your CLI is acting as
Start here. If the CLI is running as the root user, every later result is less trustworthy, and you have a problem to fix.
aws sts get-caller-identityThe output has three fields: UserId, Account, and Arn. The ARN tells you the kind of identity.
| ARN pattern | Meaning |
|---|---|
| `arn:aws:iam::111122223333:root` | You are the root user. Stop and switch to your admin identity. |
| `arn:aws:iam::111122223333:user/alice` | An IAM user. Acceptable, but prefer temporary credentials. |
| `arn:aws:sts::111122223333:assumed-role/AWSReservedSSO_.../alice` | A role session, for example from IAM Identity Center. This is the preferred pattern. |
get-caller-identity needs no IAM permissions. It works for any valid credentials, which makes it a safe first command.
Check 2: root MFA and root access keys
The account summary reports both root facts in one call.
aws iam get-account-summary \
--query 'SummaryMap.{RootMFA:AccountMFAEnabled,RootAccessKeys:AccountAccessKeysPresent}'Both values are numbers, not booleans.
| Field | Expected value | Meaning |
|---|---|---|
| `RootMFA` | `1` | MFA is active on the root user. |
| `RootAccessKeys` | `0` | The root user has no access keys. |
If you get RootMFA: 0 or RootAccessKeys: 1, go back to the earlier chapters and fix it before you continue. For an access key, deactivate it first and then delete it, after confirming nothing still uses it.
These two fields describe the root user only. They say nothing about MFA on your IAM users or about their keys. For that, use the credential report below.
The credential report
The credential report is a CSV file with one row per IAM user, plus a row named <root_account>. It is the best single source for per-identity facts.
aws iam generate-credential-report
aws iam get-credential-report --query Content --output text | base64 --decodeTwo behaviors cause most of the confusion:
generate-credential-reportcan returnState: STARTED. Wait a few seconds and run it again until it returnsCOMPLETE. If you runget-credential-reporttoo early, it fails.- AWS generates a new report at most once every four hours. A request inside that window returns the existing report. Right after you fix a problem, the report can still show the old state. The
get-account-summarycall is current, so use it to confirm the fix.
The full CSV has many columns. To see only the root row's relevant fields, cut by column position:
aws iam get-credential-report --query Content --output text \
| base64 --decode \
| cut -d, -f1,8,9,14 \
| head -n 2Field 1 is user. Field 8 is mfa_active. Fields 9 and 14 are access_key_1_active and access_key_2_active. For a healthy root user, the second line reads:
<root_account>,true,false,falseColumn positions are stable in the current format, but if you script against them, check the header row first. A parser that matches by header name is safer than one that matches by position.
Check 3: the budget and its alert
List the budgets on the account. You need the account ID, which you can read from the CLI.
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
aws budgets describe-budgets --account-id "$ACCOUNT_ID" \
--query 'Budgets[].{Name:BudgetName,Limit:BudgetLimit.Amount,Unit:BudgetLimit.Unit,Period:TimeUnit}'A budget that exists but has no notification is useless, so check the notification too.
aws budgets describe-notifications-for-budget \
--account-id "$ACCOUNT_ID" \
--budget-name monthly-cost-budgetLook for the following in the output:
NotificationTypeisACTUAL(spend that has happened), orFORECASTED(spend predicted by AWS).ThresholdandThresholdTypematch what you intended, for example80andPERCENTAGE.- A subscriber exists, which you can list with
describe-subscribers-for-notification.
Email subscribers for a budget notification do not need to be IAM users. An address with a typo, however, silently never receives anything. If you created the budget with a placeholder such as [email protected], replace it now.
Doing the same checks in the console
The console gives you a visual second opinion. You can run the console checks without the CLI.
- Security credentials page. Sign in as your administrative identity, open your account menu, and choose Security credentials. For the root user's own page you must sign in as root. If you only need confirmation, the CLI checks above are enough and avoid a root sign-in.
- IAM dashboard. The Security recommendations panel flags a root user without MFA and a root user with access keys. A green state matches
RootMFA: 1andRootAccessKeys: 0. - Billing and Cost Management, Budgets. Open your budget, then its Alerts section. Confirm the threshold, the type, and the recipient address.
- Account page. Confirm the primary contact and the alternate contacts (billing, operations, security). Those contacts receive notices that matter.
Prefer the CLI for repeated checks. It gives the same answer each time and can run on a schedule.
Putting the checks in one script
A short script turns the checks into a pass or fail result. It reads the summary, flags any problem, and exits non-zero on failure, so you can run it in a scheduled job.
#!/usr/bin/env bash
set -euo pipefail
fail=0
arn=$(aws sts get-caller-identity --query Arn --output text)
account=$(aws sts get-caller-identity --query Account --output text)
if [[ "$arn" == *":root" ]]; then
echo "FAIL: CLI is using the root user ($arn)"
fail=1
fi
read -r mfa keys < <(aws iam get-account-summary \
--query 'SummaryMap.[AccountMFAEnabled,AccountAccessKeysPresent]' \
--output text)
if [[ "$mfa" != "1" ]]; then
echo "FAIL: root MFA is not enabled"
fail=1
fi
if [[ "$keys" != "0" ]]; then
echo "FAIL: root access keys exist"
fail=1
fi
budgets=$(aws budgets describe-budgets --account-id "$account" \
--query 'Budgets[].BudgetName' --output text 2>/dev/null || true)
if [[ -z "$budgets" ]]; then
echo "FAIL: no budget found"
fail=1
fi
if [[ "$fail" -eq 0 ]]; then
echo "PASS: baseline checks succeeded for account $account"
fi
exit "$fail"The script needs permission for sts:GetCallerIdentity (always allowed), iam:GetAccountSummary, and budgets:ViewBudget. An administrative identity has these. A narrower identity might not, and then the script fails with an access error. Do not read that error as a baseline failure.
Common errors
AccessDeniedonget-account-summaryor on budgets. The identity lacks the permission. Budgets and billing data may additionally require that IAM access to billing information is activated by the root user, as covered in the billing visibility chapter.- A report that still shows old data. The four-hour credential report cache is the likely cause. Use
get-account-summaryfor a current answer. describe-budgetsreturns nothing. Either no budget exists, or you queried the wrong account. CompareAccountfromget-caller-identityagainst the account you expect.- A passing script that hides a bad alert address. The script checks that a budget exists, not that its email works. Verify delivery once by reading the subscriber and confirming the recipient receives AWS confirmation or test notices.
Exercise
You run get-account-summary and get RootMFA: 1 and RootAccessKeys: 0. Does that prove your IAM users also have MFA and no access keys? What would you use to check them, and what caveat applies to that tool?
Show answer
No. Those two fields describe only the root user. To check IAM users, generate and read the credential report, which has one row per IAM user with mfaactive and accesskey1active/accesskey2_active columns. The caveat is that AWS regenerates the report at most once every four hours, so a fix you just made may not show until a new report is generated. Also, generate-credential-report may return STARTED, so retry until it returns COMPLETE before calling get-credential-report.
Exercise
Your budget exists and describe-budgets lists it, but you never received an alert even though spending passed the threshold. Name two things you should check.
Show answer
First, run describe-notifications-for-budget and confirm a notification exists with the intended type (ACTUAL or FORECASTED), threshold, and threshold type. Second, check the subscriber address with describe-subscribers-for-notification for typos or a placeholder such as [email protected], and check spam folders. Billing data can also lag by several hours, so the alert may not have fired yet.