Treat empty AWS environment values as unset - #1845
Open
sylvesterkaczmarek wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Treat empty AWS-related environment variables as absent in the AWS client credential resolver.
The shared
_read_env()helper currently returns the first value that is notNone. That means an exported-but-empty variable is considered configured. This is common in CI and container manifests where optional secrets are declared with empty defaults.The most significant case is
ANTHROPIC_AWS_API_KEY="": its mere presence switches auth selection from the default AWS SigV4 credential chain into API-key mode, after which the resolved API key is the empty string. A harmless empty placeholder can therefore disable otherwise valid IAM/role credentials.The same helper is also used for workspace IDs and AWS base URLs, so an empty higher-priority variable can mask a later usable fallback.
Fix
Have
_read_env()return the first non-empty environment value instead of the first non-Nonevalue.Explicit constructor arguments are unchanged. The normalization applies only to environment fallback resolution, matching the SDK's existing treatment of optional environment credentials in other auth paths.
This restores expected fallback behavior:
Regression coverage
Adds focused tests for all four cases above using isolated test environment-variable names.
The production change is confined to the hand-maintained AWS credential-resolution helper.