AWS Builder Center

Automatic SSO Sign-In for Codex and Claude Code on Amazon Bedrock

Codex and Claude Code don't prompt for AWS sign-in — they just fail when credentials lapse. A 30-line credential_process helper gives every developer their own IAM Identity Center identity on Bedrock, with the browser login firing only when it's actually needed.

AWS Solutions Architect

Coding Agents Have No Login Button

Point Codex or Claude Code at Amazon Bedrock and something odd happens the first time your credentials lapse. The agent doesn't ask you to sign in. It just fails.
That surprises people, because every other tool in a developer's day knows how to prompt for a login. But these agents aren't identity clients. With a Bedrock-backed provider they ask the AWS SDK for credentials, sign with SigV4, and if the SDK comes back empty they stop. There is no prompt to show, because a browser SSO handshake belongs to  aws sso login  — not to the agent.
Here's what Codex actually reports:
ERROR: Reconnecting... 1/5
ERROR: Reconnecting... 2/5
...
ERROR: stream disconnected before completion: failed to load AWS credentials
Five reconnect attempts, though nothing was ever sent. The SDK failed locally before a single byte left the machine. We spent real time chasing network and endpoint theories before realising the message was lying to us. If you take one thing from this post: when a Bedrock-backed agent says "Reconnecting", check credentials, not connectivity.
The obvious fixes are all worse than they look. A shared Bedrock API key gets you running in a minute and destroys per-developer attribution — every request arrives as the same principal. Long-lived IAM user keys on laptops are the thing your security review exists to prevent. And "just tell developers to run  aws sso login  when it breaks" is fine until you're the third person that week explaining it in Slack.
What we wanted was per-developer identity in Bedrock's logs, no static secrets, no infrastructure to run, and a browser that appears exactly when it's needed and never otherwise. It turns out you can have all four, and the whole thing is one shell script.



The Seam:  credential_process 

 credential_process  is a standard key in the AWS shared config file. The SDK runs the command you name and reads credentials from its stdout. It exists so you can plug in custom credential sources.
The useful property is that it's an arbitrary command, and it runs at exactly the right moment — when something needs credentials and doesn't have them. Which means it can do anything first. Including opening a browser.
agent starts
└─ SDK resolves the profile
└─ runs your script
├─ cached SSO token valid? ──► print credentials, done (no browser)
└─ no valid token ──► aws sso login (browser opens)
└─ print credentials
└─ SDK signs the Bedrock request
You end up with two profiles. One is an ordinary Identity Center profile. The other wraps it:
[profile bedrock-sso]
sso_session = my-sso
sso_account_id = <ACCOUNT_ID>
sso_role_name = <PERMISSION_SET>
region = <BEDROCK_REGION>

[profile bedrock-sso-auto]
credential_process = /path/to/sso-credential-helper.sh
region = <BEDROCK_REGION>
Both reach the same account and role. Keep the plain one — it's how you check session state without side effects, which matters more than you'd think.



The Script

#!/usr/bin/env bash
# Emit AWS credentials, launching the Identity Center browser login
# when no valid SSO token is cached.
#
# CONTRACT: stdout must contain nothing but the credential JSON.
set -euo pipefail

SOURCE_PROFILE="${SSO_HELPER_PROFILE:-bedrock-sso}"
SSO_SESSION="${SSO_HELPER_SESSION:-my-sso}"
LOCK_DIR="${TMPDIR:-/tmp}/sso-credential-helper-${SSO_SESSION}.lock"

log() { printf '[sso-helper] %s\n' "$*" >&2; }

try_export() {
aws configure export-credentials --profile "$SOURCE_PROFILE" --format process 2>/dev/null
}

if creds="$(try_export)"; then
printf '%s' "$creds"; exit 0
fi

if mkdir "$LOCK_DIR" 2>/dev/null; then
trap 'rmdir "$LOCK_DIR" 2>/dev/null || true' EXIT INT TERM
log "no valid SSO token — starting browser login"
aws sso login --sso-session "$SSO_SESSION" >&2 || { log "login failed"; exit 1; }
else
log "another login in progress — waiting"
waited=0
while [ -d "$LOCK_DIR" ] && [ "$waited" -lt 180 ]; do sleep 2; waited=$((waited+2)); done
fi

if creds="$(try_export)"; then
printf '%s' "$creds"; exit 0
fi

log "still no credentials after login"
exit 1
Three things in there are load-bearing, and we got each of them wrong first.
Don't hand-build the JSON.  aws configure export-credentials --format process  emits exactly the  credential_process  v1 shape already. The helper is a thin wrapper around a command that does the hard part.
stdout purity is absolute.  aws sso login  prints a verification code and a URL. Those are helpful to a human and fatal to a credential parser — one stray byte and resolution fails with an error that points nowhere near the cause. Every diagnostic and all login output goes to stderr. We verify this the boring way: on success the script emits ~1.1 KB of pure JSON and zero bytes of stderr; on failure, zero bytes of stdout.
You need the lock. Codex retries a failed request five times, and each retry can resolve credentials independently. Without serialisation, one expired token gets a developer five browser tabs. The  mkdir  lock is atomic, and the  EXIT / INT / TERM  trap means it releases even when the login fails or someone hits Ctrl-C.

Will the agent actually wait?

This was the one assumption that could have sunk the whole approach.  aws sso login  blocks until the human finishes in the browser. If the agent gives  credential_process  a two-second budget, none of this works.
So we measured it rather than hoped. Point a profile at a script that sleeps 30 seconds and then returns valid credentials, and run the agent:
EXIT=0 ELAPSED=38s no credential errors, no retries
Codex waited. A browser login is typically 10–25 seconds, so there's headroom. Measure this in your own environment before you roll it out — it's a behaviour of the agent, not of AWS, and it can change between versions.

Why the browser almost never appears

The behaviour that makes this pleasant to live with comes from two caches that people conflate:
Cache
Scope
What it decides
SSO token in  ~/.aws/sso/cache 
on disk, shared by every process, carries a refresh token
whether a browser is needed
 credential_process  output
in memory, per process
whether the script re-runs
Every CLI invocation is a fresh process, so the helper runs every single time — about a second. But on the happy path it only reads an already-cached token and returns. The browser surfaces only after an explicit logout, or when the Identity Center session itself expires.
So: script runs constantly, browser appears roughly once a day. That's the experience you want.



Wiring Up the Agents

Codex is a two-line change:
model_provider = "amazon-bedrock"

[model_providers.amazon-bedrock.aws]
region = "<BEDROCK_REGION>"
profile = "bedrock-sso-auto"
Its built-in provider signs with SigV4 from the standard credential chain and refreshes on its own. No Codex-side login, no OpenAI account in the path ( OpenAI's setup guide ).
Claude Code reads  ~/.claude/settings.json :
{
"env": {
"CLAUDE_CODE_USE_BEDROCK": "1",
"AWS_PROFILE": "bedrock-sso-auto",
"AWS_REGION": "<BEDROCK_REGION>",
"ANTHROPIC_MODEL": "<MODEL_ID>"
}
}
One gotcha: if a key called  awsCredentialExport  is present it overrides  AWS_PROFILE  completely and your profile is silently ignored. Some managed distributions set it. If your profile appears to have no effect, look there first.
Worth noting Claude Code degrades more gracefully than Codex without the helper. Its error is actually actionable:
API Error: Token is expired. To refresh this SSO session run 'aws sso login'
with the corresponding profile.
It detects SSO expiry precisely and names the fix. So the helper is about removing friction there, not about making it work at all.
The desktop app is the interesting one: recent versions have native Identity Center sign-in. It registers an OIDC client with your Identity Center at runtime, runs a device-authorization flow, and shows an in-app Sign in with AWS page. No AWS CLI, no  credential_process , none of the above. You configure it through the app's third-party inference panel ( deployment docs ).
Which leads to the thing that confuses everyone on the team at least once: the desktop app and the CLIs sign in separately. The app stores its token in the OS keychain; the CLIs use  ~/.aws/sso/cache . Same Identity Center, same user, two independent sessions. Logging out of one does nothing to the other.



Four Things That Bit Us

These cost us the most time, and none are in an obvious place.
The IAM prefix is not what you expect. Claude models on  bedrock-runtime  need  bedrock:InvokeModel  and  bedrock:InvokeModelWithResponseStream . But OpenAI's GPT-5.x models are served through a different endpoint,  bedrock-mantle , under its own IAM service prefix —  bedrock-mantle:* , not  bedrock:*  ( service authorization reference ). A least-privilege policy built around  bedrock:InvokeModel  will pass review and then fail at runtime for exactly the models you added it for.
Model ID formats are endpoint-specific and mutually exclusive. The mantle endpoint wants bare IDs like  anthropic.claude-sonnet-5 .  bedrock-runtime  wants the cross-region inference-profile ID, prefixed with  us.  or  global. . Each returns 404 for the other's format. Don't copy IDs between a CLI config and a desktop config and expect them to work — list what your account actually serves:
aws bedrock list-inference-profiles --region <REGION> \
--query "inferenceProfileSummaries[].inferenceProfileId" --output table
 aws sso logout  is indiscriminate. It deletes every JSON file in  ~/.aws/sso/cache  whose contents contain an  accessToken  key, and there's no per-profile logout. Other tools sometimes keep their own tokens in that directory, and those get deleted too — logging developers out of unrelated applications. If that's your situation, move the unrelated files out for the duration of the sweep and back afterwards. Don't copy-and-restore: the sweeper also calls the SSO logout API for each token it finds, so a restored file may already be dead server-side.
Three different timers govern "expiry". The permission set's session duration controls how long assumed-role credentials last. The SSO access token is shorter-lived but auto-refreshes silently. And the Identity Center sign-in session — configured separately, under Identity Center settings — is what actually decides when a developer sees a browser again. We conflated the first and third for longer than we should have. If developers are re-authenticating more often than you expect, it's the third one.



What You Get, and What You Don't

Turn on  model invocation logging  and every request lands with the calling identity attached:
"identity": {
"arn": "arn:aws:sts::<ACCOUNT_ID>:assumed-role/AWSReservedSSO_<PERMISSION_SET>_.../<username>"
}
That's per-developer attribution, queryable in CloudWatch Logs Insights, with no infrastructure. For a team that mainly needs to answer "who is using this, and roughly how much" — that's the whole job, done.
Be honest about the ceiling, though. This gives you raw records, not a product. There are no aggregated per-user cost dashboards, no per-user quota enforcement, and no business dimensions like team or cost centre, because an IAM principal doesn't carry them.
If you need those, the  AWS Solutions guidance for Claude Code with Amazon Bedrock  deploys an OpenTelemetry pipeline, dashboards, and quota enforcement, using Cognito as the identity provider. It genuinely does more. It's also several CloudFormation stacks and always-on compute, so pick it when you want the reporting — not when you just want identity.
A gateway like LiteLLM or Bifrost is the third shape: per-user virtual keys, budgets, and model allowlists, at the cost of a network hop in your inference path and a service to keep alive.
We started with the assumption we'd need one of those two. We didn't. The lightest thing that solved our actual problem was a profile, a permission set we already had, and thirty lines of bash — and the main reason it isn't more widely done is that  credential_process  is a quiet corner of the AWS config format that most people never need to visit.
Worth visiting.
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