Skip to content

Add async resolver for AWS config values - #751

Open
ubaskota wants to merge 4 commits into
smithy-lang:developfrom
ubaskota:config_resolver_implementation
Open

Add async resolver for AWS config values#751
ubaskota wants to merge 4 commits into
smithy-lang:developfrom
ubaskota:config_resolver_implementation

Conversation

@ubaskota

Copy link
Copy Markdown
Contributor

Issue #, if available:

Description of changes:
This change implements the async config resolution pipeline with AsyncAwsConfig using a resolve() classmethod as the only construction path. It adds SharedConfigContext for holding memoized config file data, FieldSpec for per-field resolution metadata, and provenance tracking via ConfigSource. Resolvers for region and retry_strategy_options are included along with validators for both fields.

Testing:

  • Added unit and end-to-end tests covering env var resolution, profile resolution, explicit overrides, defaults, provenance tracking, FileSystem, validator enforcement, and construction blocking, and verified that they all pass.
  • All existing tests pass

Note: This is a revision to the old PR (#738) that was automatically closed after the feature branch was merged.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

ubaskota added 2 commits July 23, 2026 18:28
# Conflicts:
#	packages/smithy-aws-core/src/smithy_aws_core/config/exceptions.py
@ubaskota
ubaskota requested a review from a team as a code owner July 23, 2026 23:38
Comment thread packages/smithy-aws-core/src/smithy_aws_core/config/validators.py
Comment thread packages/smithy-aws-core/src/smithy_aws_core/config/validators.py Outdated
Comment thread packages/smithy-aws-core/src/smithy_aws_core/config/validators.py
Comment thread packages/smithy-aws-core/src/smithy_aws_core/config/aws_config.py
Comment thread packages/smithy-aws-core/src/smithy_aws_core/config/aws_config.py Outdated
Comment thread packages/smithy-core/src/smithy_core/exceptions.py Outdated
Comment thread packages/smithy-aws-core/src/smithy_aws_core/config/aws_config.py

region: str | None = None
retry_mode: str | None = None
max_attempts: int | None = None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are promising to return int | None for max_attempts, however, this isn't true when a customer passes in a str. We cannot violate that contract.

>>> config = await AsyncAwsConfig.resolve(max_attempts="5")
>>> type(config.max_attempts)
<class 'str'>

async def resolve(
cls,
*,
profile: str | None = None,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a customer provides a profile value that doesn't actually exist, we throw a misleading error:

>>> c>>> config = await AsyncAwsConfig.resolve(profile="FOOBAR")  from smithy_aws_core.config import AsyncAwsConfig
>>> config = await AsyncAwsConfig.resolve(profile="FOOBAR")
Traceback (most recent call last):
  File "/Users/gytndd/.local/share/uv/python/cpython-3.12.13-macos-aarch64-none/lib/python3.12/concurrent/futures/_base.py", line 456, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/gytndd/.local/share/uv/python/cpython-3.12.13-macos-aarch64-none/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "<console>", line 1, in <module>
  File "/Users/gytndd/dev/GitHub/temp6/smithy-python/packages/smithy-aws-core/src/smithy_aws_core/config/aws_config.py", line 105, in resolve
    await instance._resolve_fields(overrides)
  File "/Users/gytndd/dev/GitHub/temp6/smithy-python/packages/smithy-aws-core/src/smithy_aws_core/config/aws_config.py", line 165, in _resolve_fields
    spec.validator(getattr(self, field_name))
  File "/Users/gytndd/dev/GitHub/temp6/smithy-python/packages/smithy-aws-core/src/smithy_aws_core/config/validators.py", line 24, in validate_region
    raise ConfigValidationError(
smithy_aws_core.config.exceptions.ConfigValidationError: Invalid value for 'region': None. Region is required and must be set.

A common case will be when customers make a type in the profile name. We should provide a more accurate/helpful error.

if result.value == "legacy":
warnings.warn(
"'legacy' retry mode is not supported, using 'standard' instead.",
DeprecationWarning,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually DeprecationWarning means something works for this package today and won't in the future. We should use UserWarning instead since this is by design.

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.

2 participants