Skip to content

Instantly share code, notes, and snippets.

@bparaj
Created July 2, 2020 16:06
Show Gist options
  • Save bparaj/1c61755f73e16a33c0fb56fbcc09c551 to your computer and use it in GitHub Desktop.
Save bparaj/1c61755f73e16a33c0fb56fbcc09c551 to your computer and use it in GitHub Desktop.
Check for read/write permission on a list of s3 bucket names. Use boto3.
import boto3
# Build your list of bucket names.
s3_list = ["abc", "xyz", "my-dev-bucket"]
s3 = boto3.client('s3')
for i, bkt in enumerate(s3_list):
# Try reading first.
try:
s3.list_objects(Bucket=bkt)['Contents']
read = 1
except:
read = 0
# Writing
try:
resp = s3.put_object(
Bucket=bkt,
Key=f"test_{bkt}.txt",
Body="test",
ACL="bucket-owner-full-control",
)
write = 1
except Exception as err:
write = 0
print(f"{bkt}: r = {read}, w = {write}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment