Proposal: Respect AWS_REGION Environment Variable in STS Region Resolution #7455
      
        
          +12
        
        
          −6
        
        
          
        
      
    
  
  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.
  
    
  
    
Respect AWS_REGION Environment Variable in STS Region Resolution
Issue
Related to common issues with Kubernetes IRSA and container-based deployments where
AWS_REGIONenvironment variable is set but ignored by STS client.Description
What This Implements
This PR updates the STS client's
resolveRegionfunction to checkAWS_REGIONandAWS_DEFAULT_REGIONenvironment variables before falling back to the hardcodedus-east-1default region.Files Modified:
codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/sts-client-defaultStsRoleAssumers.tsclients/client-sts/src/defaultStsRoleAssumers.tspackages/nested-clients/src/submodules/sts/defaultStsRoleAssumers.tsCurrent Behavior (Problem)
Currently, when the AWS SDK for JavaScript v3 makes STS API calls (e.g.,
AssumeRole,AssumeRoleWithWebIdentity), it uses the following region resolution priority:regionparameterparentRegionfrom parent client configus-east-1⬅️ ProblemThis causes unexpected behavior when:
AWS_REGIONorAWS_DEFAULT_REGIONenvironment variables setReal-World Impact
In Kubernetes environments using IRSA, pods typically have these environment variables set:
Despite having the correct region configured, STS requests unexpectedly go to
us-east-1, causing:New Behavior (Solution)
The updated
resolveRegionfunction now checks environment variables:New Region Resolution Priority:
regionparameter (highest priority)parentRegionfrom parent client configAWS_REGIONenvironment variable ⬅️ NEWAWS_DEFAULT_REGIONenvironment variable ⬅️ NEWus-east-1hardcoded default (lowest priority)Why This Change is Important
1. Aligns with AWS Best Practices
AWS_REGIONandAWS_DEFAULT_REGIONAWS_REGIONautomatically2. Principle of Least Surprise
AWS_REGIONis set but ignored, it creates confusion and debugging overhead3. Container/Kubernetes Native
4. Consistency with Other SDK Components
fromTemporaryCredentialsalready usesenv.AWS_REGION(seepackages/credential-providers/src/fromTemporaryCredentials.ts)5. Prevents Unexpected Cross-Region Calls
Backward Compatibility
This change is fully backward compatible:
✅ Existing code with explicit region configuration continues to work (highest priority)
✅ Parent client region configuration still works (second priority)
✅ Applications without any region configuration still get
us-east-1(lowest priority)✅ No breaking changes to any public APIs
✅ Only adds a fallback layer before the hardcoded default
Testing
This change will be tested to verify:
AWS_REGIONenvironment variable is respected when setAWS_DEFAULT_REGIONis used as fallback ifAWS_REGIONis not setus-east-1when no region is configured anywhereTest Plan
Additional Context
Benefits Summary
Related Use Cases
This change addresses common pain points:
References
Checklist
*.integ.spec.ts).@publictag and enable doc generation on the package?By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.