AWS Builder Center
Why Did Two Apps Talking to Each Other Rack Up Our AWS Bill?

Why Did Two Apps Talking to Each Other Rack Up Our AWS Bill?

Every time one app asked AWS to confirm another app's identity, we got billed — with zero free allowance. Here's what "machine-to-machine" login actually means, and the free fix we found.

Tech Enthusiast

Before we start: four quick definitions

  • Authentication is proving who (or what) you are. Authorization is what you're allowed to do once you've proven it. This article is about proving identity — specifically for two programs talking to each other, no human involved.
  • OAuth 2.0 client credentials flow is the standard way one app proves its identity to another, without a person logging in. Think staff ID badge: App A shows a secret badge number, gets handed a temporary pass back.
  • A JWT (JSON Web Token) is that temporary pass — a small, signed piece of text saying "yes, this request is really from App A, and it expires at [time]." Whoever receives it can check the signature without calling anyone to confirm it's real.
  • Amazon Cognito is AWS's identity service — it can issue these passes. Amazon API Gateway is AWS's front door for APIs — it can check whether an incoming pass is valid before letting the request through.
With that, here's what went wrong.

The problem: a "free" login flow that wasn't

We had a backend service, running outside AWS, calling an API behind Amazon API Gateway. To prove its identity on every call, it used the client credentials flow against Amazon Cognito: ask for a badge, present the badge, get access.
The bill didn't match how simple the pattern is supposed to be. Cognito's pricing explained why: it charges for every single badge it hands out, and unlike its regular per-user pricing, this specific charge has no free allowance at all — the first badge costs the same, per badge, as the millionth.
That's the whole story. If your app asks for a fresh badge on every single API call instead of reusing one until it expires, your bill scales with how often you call the API, not with how many services you have. One service calling once a second, with no reuse, is roughly 2.6 million badge requests a month. Priced per badge with nothing free, that adds up fast.

The idea: skip the paid badge office

We already run a separate identity system for internal apps — the kind normally used for employee logins — and using that same client credentials flow against that system instead doesn't cost anything extra. It's bundled into a license we already pay for.
Obvious question: if we already have a badge office that hands out the same kind of badge for free, why pay a second one to do the identical job?

The fix: let the front door check a different office's badge

Key piece of AWS knowledge that made this work: API Gateway's badge checker (its "JWT authorizer") doesn't require badges to come from Cognito. It can trust any standards-compliant identity provider — including the one we already had.
New setup:
  1. The calling service asks our existing identity provider for a badge — not Cognito.
  1. API Gateway is configured to trust that provider directly, checking the badge's signature, issuer, and intended audience, same as it would have for a Cognito badge.
  1. Cognito is removed from this flow entirely. No more per-badge charge, because nothing is asking Cognito for badges anymore.
The calling service still gets a fresh badge on the same cadence as before — what changed is which office issues it, and that office doesn't charge per badge.

Worth knowing if you build this yourself

  • Only works with one flavor of API Gateway ("HTTP APIs"). The other flavor ("REST APIs") needs a small custom piece of code to check the badge instead of a built-in checker — more setup, still far cheaper than paying per badge.
  • The "what you're allowed to do" info sits in a different field for app-to-app badges than for human-user badges. Worth checking this specifically if permission checks silently don't work — it's a common gotcha, not a sign the approach is broken.
  • Not automatically free forever. Identity providers are starting to charge for very large numbers of distinct apps authenticating — but the free thresholds tend to be generous (tens of thousands), so for a normal number of internal services this realistically stays free.
  • Only works if you control the caller's identity. If the calling app belongs to an outside company with its own login system, you can't point it at your identity provider. Cognito or a simple API key is still the practical choice there.

What to take away

If you're a student: a good concrete example of how "free-sounding" cloud services can hide pricing edges — and how understanding what a service is actually doing under the hood (issuing and checking signed tokens) lets you spot when you're paying twice for the same job.
If you're already working with this professionally: before optimizing usage of a paid managed service, check whether you're already paying — through a completely different bill — for something that does the exact same job for the exact same protocol. The cheapest fix here wasn't tuning the expensive service. It was removing it.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article