Skip to content

Support AWS_REGION env var, cluster context fallback, and centralize boto3 client creation#395

Open
FarhanTejani wants to merge 1 commit intoaws:mainfrom
FarhanTejani:refactor/centralize-boto3-and-region-resolution
Open

Support AWS_REGION env var, cluster context fallback, and centralize boto3 client creation#395
FarhanTejani wants to merge 1 commit intoaws:mainfrom
FarhanTejani:refactor/centralize-boto3-and-region-resolution

Conversation

@FarhanTejani
Copy link
Member

What's changing and why?

Two related changes:

1. Fix AWS_REGION env var being ignored (closes #357)

The CLI ignores the AWS_REGION environment variable. The AWS CLI respects both AWS_REGION and AWS_DEFAULT_REGION, but boto3 only checks AWS_DEFAULT_REGION. This is confusing for users who expect consistent behavior.

This change introduces a _resolve_region function with the following fallback order:

  1. Explicit --region flag
  2. AWS_REGION env var
  3. AWS_DEFAULT_REGION / ~/.aws/config (standard boto3 chain)
  4. Region from current cluster context (extracted from the EKS ARN set by 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 existing create_boto3_client utility. 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 through create_boto3_client, and unused boto3 imports are removed. The only remaining direct boto3 usage is in utils.py (where create_boto3_client is defined) and cluster.py (which uses boto3.Session for credential validation).

Before/After UX

Before:

$ AWS_REGION=us-west-2 hyp list-cluster
# ERROR - Please ensure you have configured the AWS default region

After:

$ AWS_REGION=us-west-2 hyp list-cluster
# Works, lists clusters in us-west-2

After set-cluster-context:

$ hyp set-cluster-context --cluster-name my-cluster --region us-west-2
$ hyp list-cluster
# Works without --region, uses region from cluster context

How was this change tested?

  • Unit tests pass
  • Verified AWS_REGION=us-west-2 hyp list-cluster returns cluster data
  • Verified AWS_DEFAULT_REGION still works
  • Verified --region flag still takes precedence
  • Verified inference commands using get_current_region() are unaffected

Are unit tests added?

Yes, added tests for _resolve_region:

  • Explicit region takes precedence over env vars
  • AWS_REGION env var is used when no explicit region
  • Falls back to boto3 default when no env var
  • Falls back to cluster context when boto3 has no region
  • Returns None when nothing is configured

Are integration tests added?

N/A

Reviewer Guidelines

‼️ Merge Requirements: PRs with failing integration tests cannot be merged without justification.

One of the following must be true:

  • All automated PR checks pass
  • Failed tests include local run results/screenshots proving they work
  • Changes are documentation-only

@FarhanTejani FarhanTejani requested a review from a team as a code owner March 19, 2026 00:31
@FarhanTejani FarhanTejani deployed to manual-approval March 19, 2026 00:31 — with GitHub Actions Active
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.

AWS_REGION is ignored

2 participants