Created
July 2, 2020 16:06
-
-
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.
This file contains 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
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