Skip to content

Raise clear error when s3 config block is a plain string#10307

Open
shreyaskommuri wants to merge 2 commits into
aws:developfrom
shreyaskommuri:fix/s3-config-block-error-handling
Open

Raise clear error when s3 config block is a plain string#10307
shreyaskommuri wants to merge 2 commits into
aws:developfrom
shreyaskommuri:fix/s3-config-block-error-handling

Conversation

@shreyaskommuri
Copy link
Copy Markdown

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:

'str' object has no attribute 'get'

The root cause: scoped_config.get('s3', {}) returns '' instead of {} because the key exists — Python's dict.get only 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 an isinstance check at the top of S3TransferCommand._run_main. If s3 is a plain string rather than a nested section, raises InvalidConfigError immediately 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:

$ aws s3 cp ... 
'str' object has no attribute 'get'

After:

Invalid value for 's3' in your AWS config file. The s3 section must
use indented sub-keys, not a plain string value. For example:

s3 =
  max_concurrent_requests = 10

Test plan

  • tests/unit/customizations/s3/test_subcommands.py::TestS3ConfigValidation::test_plain_string_s3_config_raises_invalid_config_error
  • Manually verify the error message is surfaced correctly when s3= appears bare in ~/.aws/config

Written, reviewed, and tested by shreyaskommuri. AI used for context and guidance.

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.
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.

Better error handling for s3 configuration blocks

1 participant