Repository navigation
fix(train): lazily create AIRHub boto3 clients to avoid NoRegionError on import - #6401
Open
AkshayShah03 wants to merge 1 commit into
Open
AkshayShah03 wants to merge 1 commit into
AkshayShah03 wants to merge 1 commit into
Conversation
… on import AIRHub created boto3 sagemaker/s3 clients as class attributes, so they were constructed at import time. Since model_builder imports MultiTurnRLTrainer, 'import sagemaker.serve' transitively imports AIRHub and raises NoRegionError in any environment without an AWS region configured. Create the default clients on first use via _get_sagemaker_client() and _get_s3_client() and cache them on the class. The attributes are kept so existing callers/tests that assign mock clients keep working.
AkshayShah03
requested a deployment
to
manual-approval
October 9, 2026 17:51 — with
GitHub Actions
Waiting
AkshayShah03
requested a deployment
to
manual-approval
October 9, 2026 17:51 — with
GitHub Actions
Waiting
AkshayShah03
requested a deployment
to
manual-approval
October 9, 2026 17:51 — with
GitHub Actions
Waiting
This branch is waiting to be deployed
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.
Issue #, if available: N/A (same problem as closed, unmerged #5935)
Description of changes:
AIRHubcreated its defaultboto3.client("sagemaker")andboto3.client("s3")as class attributes, so they were built at import time.model_builder.pyimportsMultiTurnRLTrainer, which importsAIRHub, soimport sagemaker.serveraisesNoRegionErroron any machine or CI job without an AWS region configured:This change creates the default clients on first use, through
_get_sagemaker_client()and_get_s3_client(), and caches them on the class. The_sagemaker_client/_s3_clientattributes are kept (defaultNone), so code and tests that assign mock clients to them keep working.Testing:
test_import_does_not_require_aws_region: imports the module in a subprocess with no region or credentials configured. It fails before this change and passes after.test_clients_created_lazily_and_cached: each client is created once, on first use.sagemaker-train/tests/unit/ai_registry: 98 passed (96 before, plus the 2 new tests).import sagemaker.core, sagemaker.train, sagemaker.serve, sagemaker.mlopsnow succeeds with no region configured.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.