Support AWS_REGION env var, cluster context fallback, and centralize boto3 client creation#395
Open
FarhanTejani wants to merge 1 commit intoaws:mainfrom
Conversation
…boto3 client creation
mollyheamazon
approved these changes
Mar 19, 2026
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.
What's changing and why?
Two related changes:
1. Fix
AWS_REGIONenv var being ignored (closes #357)The CLI ignores the
AWS_REGIONenvironment variable. The AWS CLI respects bothAWS_REGIONandAWS_DEFAULT_REGION, but boto3 only checksAWS_DEFAULT_REGION. This is confusing for users who expect consistent behavior.This change introduces a
_resolve_regionfunction with the following fallback order:--regionflagAWS_REGIONenv varAWS_DEFAULT_REGION/~/.aws/config(standard boto3 chain)set-cluster-context)Step 4 means that after running
hyp set-cluster-context, subsequent commands automatically use that cluster's region without needing--region.2. Centralize boto3 client creation
The codebase had 13 direct
boto3.client()calls scattered across files, bypassing the existingcreate_boto3_clientutility. This meant any cross-cutting concern (region resolution, user-agent, retry config) had to be patched in N places instead of one.All direct
boto3.client()calls are now routed throughcreate_boto3_client, and unusedboto3imports are removed. The only remaining directboto3usage is inutils.py(wherecreate_boto3_clientis defined) andcluster.py(which usesboto3.Sessionfor credential validation).Before/After UX
Before:
After:
After
set-cluster-context:How was this change tested?
AWS_REGION=us-west-2 hyp list-clusterreturns cluster dataAWS_DEFAULT_REGIONstill works--regionflag still takes precedenceget_current_region()are unaffectedAre unit tests added?
Yes, added tests for
_resolve_region:AWS_REGIONenv var is used when no explicit regionNonewhen nothing is configuredAre integration tests added?
N/A
Reviewer Guidelines
One of the following must be true: