Skip to content

fix: update error messages when users don't pass region or profile - #962

Closed
cchu-ld wants to merge 7 commits into
mainfrom
cchu/aws-profile-errors
Closed

cchu-ld wants to merge 7 commits into
mainfrom
cchu/aws-profile-errors

Conversation

@cchu-ld

@cchu-ld cchu-ld commented Oct 23, 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

Related issues

None.

Describe the solution you've provided

aws sso login --profile <name> does not select a profile for later commands. If a user does not pass --profile to ldcli aws-devops-agent setup, the SDK uses the default profile. The old errors did not always tell the user about --profile, and they did not show which profiles exist.

This PR changes the errors from NewClients:

  • Each error gives the fixes in one sentence, easiest first, with OR between them: pass --profile, then run export AWS_PROFILE=<name>, then add a profile with aws configure sso or aws login. If no profile is selected, the error suggests the default profile, because the SDK uses it with no flag.
  • The profile list shows the account and role of each profile, from sso_account_id and sso_role_name or from role_arn. It shows five profiles at most. If it does not show all of them, it names aws configure list-profiles.
  • If no profile is selected, no default profile exists, and no region is found, the error reports the missing profile, not the missing region. A selected profile often has a region.
  • If the SDK falls back to the default profile and that profile fails, the error tells the user how to select another profile, and it lists the other profiles.
  • If the selected profile is not in the AWS files, for example after a typo, the error says so and lists the profiles. Before, the user got the SDK load error.
  • ErrNoRegion uses the same format, and it tells the user that the region can come from the AWS profile.

The help text for aws-devops-agent now gives the order of the profile and region sources.

Example, from a computer with no default profile:

no AWS profile selected.

To fix this, pass --profile <name> with a profile from the list below, OR run `export AWS_PROFILE=<name>`, OR add the default profile with `aws configure sso --profile default` for SSO, or `aws login --profile default` for an AWS console session.

Profiles:
  launchdarkly-default             554582317989  PowerUser
  commercial-production            554582317989  PowerUser
  commercial-production_PowerUser  554582317989  PowerUser
  commercial-production_Viewer     554582317989  Viewer
  commercial-dr                    554582317989  PowerUser
  and 63 more. Run `aws configure list-profiles` to see all of them

Additional context

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

🤖 Generated with Claude Code


Note

Overview
Improves AWS credential and region failures for the hidden aws-devops-agent commands so users get actionable guidance instead of opaque SDK errors.

NewClients and errors: Missing or invalid profiles are handled explicitly (including SDK “profile does not exist”), and when there is no region but named profiles exist and nothing is selected, the CLI surfaces “no profile selected” before “no region”. ErrNoRegion now lists fixes (--region, AWS_REGION, or region on the profile). Credential errors use a consistent “To fix this, … OR …” pattern (--profile, export AWS_PROFILE, aws configure sso / aws login). Profile lists are tabular (name, account, role from config), show up to 10 profiles, and when the default chain fails without an explicit profile, messages suggest picking another profile from the list.

Docs: Command long help and --region flag text describe resolution order: --profile → AWS_PROFILE → default, and --region → AWS_REGION → profile.

Tests are updated and expanded for the new message shapes and edge cases.

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

cchu-ld and others added 3 commits October 23, 2026 13:50
If no profile is selected and no region is found, the error now reports
the missing profile first, because a profile can give the region.

If the default profile fails and other profiles exist, the error tells the
user to pass --profile or set AWS_PROFILE, and it lists the profiles.

If a profile uses aws login, the error tells the user to run aws login.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ands

The error names aws login only if the SDK asks the user to authenticate
again. Other aws login errors point to aws sts get-caller-identity.

The errors now show export commands for AWS_REGION, AWS_PROFILE, and the
access keys.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The advice depended on the text of SDK errors. Without it, the error tells
the user to run aws sts get-caller-identity, which names aws login.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cchu-ld cchu-ld changed the title fix: tell the user which AWS profile to use when credentials fail fix: update error messages when users don't pass region or profile Oct 23, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cchu-ld
cchu-ld marked this pull request as ready for review October 23, 2026 22:58
@cchu-ld
cchu-ld requested a review from a team as a code owner October 23, 2026 22:58
@cchu-ld
cchu-ld requested review from wchieng and removed request for a team October 23, 2026 22:58
The credentials and region errors now give the fixes in one sentence,
easiest first, with OR between them. The profile list shows the account
and role of each profile, and names aws configure list-profiles when it
does not show all of them.

A profile that is not in the AWS files now gets this error, not the
SDK load error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cchu-ld
cchu-ld requested a review from a team October 23, 2026 23:59
A new profile from aws configure sso --profile <name> is not selected, so
the next run fails again. The SDK uses the default profile with no flag.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cchu-ld cchu-ld closed this Oct 24, 2026
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