Interview Prep/Python for DevOps/AWS automation with boto3

How would you write a Python script that enforces "no public S3 buckets" across accounts?

IntermediateScenarioAWS automation with boto3
Answer

Situation read → Detection and remediation; prevention is better.

What I'd do →

  1. Prevent first: account-level S3 Block Public Access (s3control.put_public_access_block) and an SCP that denies changing it.
  2. Detect: for each bucket, check get_public_access_block, bucket policy status (get_bucket_policy_status returns IsPublic), and ACLs; handle NoSuchPublicAccessBlockConfiguration as "not set".
  3. Remediate with an allow-list for intentional public buckets (static sites behind CloudFront should use OAC instead).
  4. Report findings; auto-remediate only with approval.

Why → Account-level controls stop the problem; scripts verify they stay on.

Interview tip → Mention get_bucket_policy_status; it saves you parsing policies yourself.

All Python for DevOps questions Roadmap: Python for automation

More on AWS automation with boto3