
A Daily Cognito Security Check That Bills Every Account
Why a daily Cognito audit job can bill every account as MAU, what ListUsers costs instead, and an event-driven check with CloudTrail and EventBridge.
I'm designing a multi-tenant SaaS with every customer in one Cognito user pool, about 200 users each, self sign-up off and TOTP required for administrators. The plan includes a daily job that catches two things: email changes that didn't come through the operator path, and administrators without TOTP.
Written the obvious way, that job turns every account into a billable user.
Why AdminGetUser is the expensive part
Checking a user's email and TOTP state means calling
AdminGetUser , which returns the attributes and UserMFASettingList . Its API reference is explicit: the operation "contributes to your monthly active user (MAU) count for the purpose of billing."Call it on every user once a day and MAU stops measuring activity. It measures accounts. On Essentials (10,000 MAU free, then $0.015 each), assuming 40% of accounts sign in during a month:
Customers | Accounts | Job reads every account | Only real activity |
|---|---|---|---|
50 | 10,000 | $0 | $0 |
200 | 40,000 | $450 | $90 |
500 | 100,000 | $1,350 | $450 |
The 40% is an assumption for the example. The free tier is per account or per AWS organization, so a staging pool running the same job eats into the same 10,000.
ListUsers: recommended, but not free in other ways
The Cognito developer guide says the MAU category for admin attribute queries includes
AdminGetUser "but not ListUsers", and recommends ListUsers to avoid the cost. I couldn't find anyone confirming that on a real invoice, but it's documented.For this job it has three problems:
- No per-tenant scoping. The only service-specific IAM condition keys for user pools are tag keys. With all customers in one pool, the role that runs the job can read every customer's email addresses.
ListUserscan't filter on custom attributes either, socustom:tenant_idis out.
- No TOTP state. It returns
MFAOptions, which covers SMS only. TOTP lives inUserMFASettingList, which onlyAdminGetUserreturns.
- Eventually consistent. The API reference itself says to use
AdminGetUserto validate an individual user.
Reacting to changes instead of reading everyone
The job exists to notice a change. CloudTrail already records user pool API calls as management events, with the user's
sub instead of the username. An EventBridge rule can match the calls that change an email or an MFA setting:{ "source": ["aws.cognito-idp"], "detail-type": ["AWS API Call via CloudTrail"], "detail": { "eventSource": ["cognito-idp.amazonaws.com"], "eventName": [ "AdminUpdateUserAttributes", "UpdateUserAttributes", "VerifyUserAttribute", "VerifySoftwareToken", "SetUserMFAPreference", "AdminSetUserMFAPreference" ] }}A small function ignores calls from the operator role, then reads only that one user with
AdminGetUser and compares the result with the application's own record. The users it reads have just done something, so they're already active for the month.Two caveats I'd want any reader to see. I haven't verified that every event in that rule reaches EventBridge; one public project reports an event type that never arrived. And this design sees actions, not state, so a small daily job stays in place for administrators' TOTP only.
One more thing worth checking
If your early warning is an AWS Budgets usage budget on Cognito MAU, it may not fire before billing starts. AWS's free tier tracking list doesn't name an Essentials usage type, and another project reports its alert arriving with the first charge. Counting tenants in your own database is a control you can trust.
The full design review, with the alert timeline, the AdminGetUser and ListUsers comparison, the function sketch and a table of what's documented versus not verified: https://rafael-gross.com/writing/aws-cognito-audit-job-mau/
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article