Repository navigation
feat: ask for an AWS profile and region when the default credentials fail - #967
Conversation
…fail If no profile is selected and the default credentials do not work, setup and status ask which profile to use. The picker lists the profiles with an SSO session first, with the account, region, and role of each. It shows 10 profiles at most and scrolls in place. Press / to search. If the profile has no region, the command asks for one. Without a terminal, the command does not ask. With --yes, it uses the one signed-in profile. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…light The huh select moved its window to the highlighted row on every key, so the highlight stayed on the first row and the rows above it were hidden. The new picker shows all rows of a list with 10 rows or fewer. In a longer list, the highlight moves down to the last row, and then the list scrolls under it. Typing searches at once, and Esc clears the search. The title and the highlighted row use the accent color of the sync pickers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit af70fbd. Configure here.
Andrewjeska
left a comment
There was a problem hiding this comment.
nits:
1)
I dont know if it's expected or not, but when I'm prompted y/N, my default is to hit "enter" without thinking because I assume that it will "do the thing".
I think the default should be yes, take a look at npm package init to see what I mean
For consistency, can we make this selectable like the profiles are?
Overall this is really great work!!
Andrewjeska
left a comment
There was a problem hiding this comment.
A few suggestions, nothing blocking — nice PR.
cmd/aws_devops_agent/clients.go:117-127 — on ErrNoRegion the region-pick path re-runs newClients once with the picked region, and if that returns ErrNoCredentials control falls through into the SSO-login block below. The logic is right but takes a minute to trace. A one-line comment on clientsAfter making the fall-through intent explicit would help.
cmd/aws_devops_agent/clients.go:74 — the errors.Is(err, awsdevops.ErrNoRegion) && !awsdevops.HasProfile("default") disjunct is dense. The reason (no default profile → SDK's region error is really "no profile at all") is above the branch, but pulling it into a named helper like noProfileReason(err) would let the branch read in one line.
internal/awsdevops/profiles.go:868 (DefaultFallback) — only checks AWS_ACCESS_KEY_ID, so it returns true when the user is actually authenticated via AWS_SESSION_TOKEN-only creds, web-identity, or container/EC2 metadata. In those cases newClients succeeds and we skip the picker, so it works — but by accident. A short comment that this is intentional and relies on newClients not returning ErrNoCredentials for ambient creds would help a future reader.
cmd/aws_devops_agent/picker.go:239-258 (profileLabels) — len(p.Name) / len(p.Account) / len(p.Region) are byte lengths. A profile name with multibyte chars would misalign the columns. ansi.StringWidth is already imported in pickermodel.go and would fix it.
Minor:- pickermodel.go:788 — filter() lowercatroke. Fine for today's sizes;pre-lowercasing in newPicker would scale a larger list.
load()ends up parsing~/.aws/configup to 3× (DefaultFallback→HasProfile→Profiles). Negligible unless the file is huge.- Picker renders to
cmd.ErrOrStderr()but theUsing AWS profile X…confirmation goes tol.out. Intentional?
via LD Research 🤖
…e the picker for the agent space If the default profile has no region, ldcli now tries the default credentials again with a supported region. If they do not work, ldcli asks for a profile, not for a region. The agent space list now uses the picker of the profile and region questions. The highlight starts on the row that was the default. The aws sso login question and the setup confirmation now use [Y/n], so Enter accepts. If the input ends with no answer, the result is a no. The profile labels now measure columns in terminal width, so a wide character does not move the columns. The picker makes the lowercase labels one time, not on each key. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er did not name If the agent space is not clear, the highlight now starts on "provision a new agent space", so Enter does not connect to a space of another owner. If the default profile uses SSO and its token is expired, ldcli now offers aws sso login for that profile and does not open the profile picker. With --yes, ldcli picks the one signed-in profile only in a terminal. The picker highlight now gets its color support from the picker output, not from stdout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@Andrewjeska Thanks for the review! Fixed in
|

Requirements
Describe the solution you've provided
With this PR, if no profile is selected and the default credentials do not work,
setupandstatusask which profile to use:~/.aws/configand~/.aws/credentials. It shows the account, region, and role of each profile. It reads only those keys, so a secret access key never leaves the file.~/.aws/sso/cachehas a✓and comes first. All the profiles that share an SSO session share one token.Using AWS profile X. To skip this question, pass --profile X or run export AWS_PROFILE=X.aws sso loginoffer runs after the choice.aws sso login --profile defaultand does not open the picker. This keeps the run in the account of the default profile. If the user answers no, the command returns the error, which names--profile. It does not go back to the picker.--yes.--yesin a terminal, the command uses the one signed-in profile if there is exactly one, and printsUsing AWS profile X. It asks for no confirmation. Before this PR, the same run returned the error. Otherwise it returns the current error.--profile,AWS_PROFILE, orAWS_ACCESS_KEY_IDskips the picker.The agent space question in
setupnow uses the same picker, in place of the numbered list. If a space matches--agent-space-name, or if setup made exactly one space, the highlight starts on that space. If the choice is not clear, the highlight starts on "provision a new agent space", so Enter does not connect to a space of another owner.The
aws sso loginquestion and the setupContinue?question now use[Y/n], so Enter accepts. If stdin closes with no answer, the result is a no.The picker is a small
bubbleteamodel with abubblestext input. It runs inline, not in the alternate screen, so the output above it stays visible. It cuts each line to the terminal width, because a wrapped line breaks the redraw. It uses the accent color of thesyncpickers, and it gets its color support from stderr, where it draws. Thehuhselect was not usable here: inhuhv1.0.0,Select.Updatesets the window offset to the highlighted row on every key, so the highlight stayed on the first row.Describe alternatives you've considered
#962 improves the error messages and does not ask. It lists five profiles with account and role, and tells the user to pass
--profile. The two PRs can merge together. They both changeNewClientserrors andloadClients, so the second one to merge needs a small rebase.Additional context
A
✓uses only the access token in the SSO cache. A session with an expired access token and a refresh token shows no✓, but the SDK can still refresh it. This changes only the sort order and the--yescount.The command is hidden, so users do not see this yet.
To try it, unset
AWS_PROFILEandAWS_REGION, make sure that no default profile works, and run./ldcli aws-devops-agent status.🤖 Generated with Claude Code
Note
Overview
When default AWS credentials fail, setup and status now walk users through credentials interactively instead of failing immediately. A searchable terminal picker (bubbletea) lists profiles from shared AWS config—SSO-signed-in profiles first with a ✓—and can prompt for a supported region if none is set. The chosen profile is written back to
--profile, with hints to skip future prompts. Expired default SSO still triggersaws sso loginrather than switching accounts;--yesauto-picks when exactly one SSO profile is signed in.The same picker replaces numbered prompts for agent space selection during setup. Highlight defaults are safer: ambiguous cases start on “provision a new agent space” so Enter won’t attach to someone else’s space. Continue? and SSO login prompts flip to
[Y/n](Enter = yes) via sharedreadYes.New
internal/awsdevops/profilesparses config/credentials for display metadata only (no secret keys) and checks SSO cache expiry.Reviewed by Cursor Bugbot for commit 963dfc0. Bugbot is set up for automated code reviews on this repo. Configure here.