Skip to content

feat: ask for an AWS profile and region when the default credentials fail - #967

Open
cchu-ld wants to merge 2 commits into
mainfrom
cchu/aws-profile-picker
Open

cchu-ld wants to merge 2 commits into
mainfrom
cchu/aws-profile-picker

Conversation

@cchu-ld

@cchu-ld cchu-ld commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Describe the solution you've provided
With this PR, if no profile is selected and the default credentials do not work, setup and status ask which profile to use:

Screenshot 2026-10-23 at 5 44 37 PM
  • The picker reads the profiles from ~/.aws/config and ~/.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.
  • A profile with a valid SSO token in ~/.aws/sso/cache has a ✓ and comes first. All the profiles that share an SSO session share one token.
  • The picker shows all the 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, so the picker never takes more than 10 rows. Type to search by substring, ignoring case. The search matches any part of the line, for example an account ID or a role. Esc clears the search, and a second Esc or Ctrl+C closes the picker.
  • After the choice, the command prints Using AWS profile X. To skip this question, pass --profile X or run export AWS_PROFILE=X.
  • If the profile has no region, the command asks for one of the supported regions in the same way.
  • If the selected profile has an expired SSO token, the current aws sso login offer runs after the choice.
  • Without a terminal, the command does not ask and returns the current error. With --yes, it uses the one signed-in profile if there is exactly one. Otherwise it returns the current error.
  • A working default profile, --profile, AWS_PROFILE, or AWS_ACCESS_KEY_ID skips the picker.

The picker is a small bubbletea model with a bubbles text 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 the sync pickers. The huh select was not usable here: in huh v1.0.0, Select.Update sets 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 change NewClients errors and loadClients, so the second one to merge needs a small rebase.

Additional context

The command is hidden, so users do not see this yet.

To try it, unset AWS_PROFILE and AWS_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 and no profile is explicitly selected, aws-devops-agent setup/status now guide setup in an interactive terminal: a searchable bubbletea picker for profile (SSO-signed-in profiles first, with ✓) and, if needed, for a supported region. The chosen profile is written back to --profile and the user gets hints to set AWS_PROFILE / AWS_REGION.

Client loading is refactored through ssoLogin.load / clientsAfter: profile prompting runs only on “default fallback” (no --profile/AWS_PROFILE/env keys); non-TTY and --yes keep prior behavior (--yes auto-picks the sole signed-in SSO profile). Existing aws sso login on expired tokens still runs after resolution.

New internal/awsdevops profile discovery parses ~/.aws/config and credentials for display metadata only (no secret keys), checks SSO cache token expiry, and exposes DefaultFallback / HasProfile. Command help text documents the flow. Broad unit tests cover load paths and picker UX (search, scroll, cancel).

Reviewed by Cursor Bugbot for commit af70fbd. Bugbot is set up for automated code reviews on this repo. Configure here.

cchu-ld and others added 2 commits October 23, 2026 17:29
…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>
@cchu-ld
cchu-ld marked this pull request as ready for review October 24, 2026 00:48
@cchu-ld
cchu-ld requested a review from a team as a code owner October 24, 2026 00:48
@cchu-ld
cchu-ld requested review from a team and nieblara and removed request for a team October 24, 2026 00:48

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ 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.

noProfile := errors.Is(err, awsdevops.ErrNoCredentials) ||
errors.Is(err, awsdevops.ErrNoRegion) && !awsdevops.HasProfile("default")
if !noProfile {
return l.clientsAfter(ctx, region, profile, clients, err)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default section skips profile picker

High Severity

A [default] section with no region makes load treat missing region as a selected profile, so the picker never runs. NewClients fails on region before credentials, and clientsAfter then asks for a region and retries default instead of asking which profile to use. A leftover empty or output-only [default] is enough to trigger this when AWS_REGION is unset.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit af70fbd. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant