Raise clear error when s3 config block is a plain string#10307
Open
shreyaskommuri wants to merge 2 commits into
Open
Raise clear error when s3 config block is a plain string#10307shreyaskommuri wants to merge 2 commits into
shreyaskommuri wants to merge 2 commits into
Conversation
MD5 is a valid checksum algorithm for S3 operations but was missing from the --checksum-algorithm choices list, causing the CLI to reject it with an invalid choice error before the request was made. This change adds MD5 to the accepted choices alongside the other supported algorithms (CRC32, SHA256, SHA1, etc.). Companion fix in botocore registers the Md5Checksum implementation so the checksum is computed correctly at the request layer. Fixes aws#10295 Generated by AI tools, and reviewed by shreyaskommuri
When a user writes s3= (bare, no nested content) in their AWS config
file, scoped_config.get('s3', {}) returns '' instead of {} because the
key exists. Downstream code then calls .get() on that string and crashes
with 'str' object has no attribute 'get', with no indication the problem
is in the config file.
Add an isinstance check at the top of S3TransferCommand._run_main that
raises InvalidConfigError with a clear message and example before any
other work is done.
Fixes aws#9469
Written, reviewed, and tested by shreyaskommuri. AI used for context and guidance.
1 task
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.
Summary
Fixes #9469.
When a user writes
s3=(bare, with no indented sub-keys) in their AWS config file, the CLI crashes with a cryptic Python error:The root cause:
scoped_config.get('s3', {})returns''instead of{}because the key exists — Python'sdict.getonly uses the default when the key is absent. Downstream code then calls.get()on that string and crashes with no hint that the config file is the problem.Changes
awscli/customizations/s3/subcommands.py: Added anisinstancecheck at the top ofS3TransferCommand._run_main. Ifs3is a plain string rather than a nested section, raisesInvalidConfigErrorimmediately with a clear message and a correctly-formatted example.tests/unit/customizations/s3/test_subcommands.py: New test covering the bad-config case.A companion fix in botocore covers the same pattern in
ClientEndpointBridge._is_s3_dualstack_mode(boto/botocore#XXXX).Before / After
Before:
After:
Test plan
tests/unit/customizations/s3/test_subcommands.py::TestS3ConfigValidation::test_plain_string_s3_config_raises_invalid_config_errors3=appears bare in~/.aws/configWritten, reviewed, and tested by shreyaskommuri. AI used for context and guidance.