Skip to content

Add S3 access validation script - #1

Open
chengjianshia wants to merge 1 commit into
mainfrom
codex/create-script-for-amazon-s3-login
Open

Add S3 access validation script#1
chengjianshia wants to merge 1 commit into
mainfrom
codex/create-script-for-amazon-s3-login

Conversation

@chengjianshia

Copy link
Copy Markdown
Owner

Motivation

  • Provide a tiny CLI tool to validate access to an S3 bucket using credentials supplied via flags, environment variables, or AWS profiles.
  • Allow quick verification of both bucket existence/permissions and optional list access under a --prefix.
  • Reduce friction when diagnosing AWS credential or configuration problems during development or CI.

Description

  • Add executable s3_login.py which implements argument parsing via argparse and credential resolution.
  • Create a boto3 Session supporting direct credentials or a profile_name and construct an S3 client.
  • Perform head_bucket to validate bucket access and optionally call list_objects_v2 with MaxKeys=1 to test prefix listing.
  • Print a clear success message on verification and diagnostic error output on failures, exiting with non-zero on errors.

Testing

  • No automated tests were run for this change.

Codex Task

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread s3_login.py
Comment on lines +58 to +61
credentials = resolve_credentials(args)
session = boto3.Session(**{k: v for k, v in credentials.items() if v})
if session_kwargs:
session = boto3.Session(**session_kwargs, **{k: v for k, v in credentials.items() if v})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Honor --profile over ambient credentials

When --profile is supplied, the code still merges in credentials from flags and environment (resolve_credentials), and then passes them alongside profile_name to boto3.Session. In boto3, explicit credential arguments take precedence, so if a user has AWS_ACCESS_KEY_ID/SECRET exported (a common case in CI or local shells), the profile is silently ignored and the access check is performed against the wrong account. This defeats the purpose of --profile and can lead to false positives/negatives when validating bucket access for another profile. Consider omitting env/flag credentials when --profile is set (or explicitly erroring on conflicts).

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant