Skip to content

Instantly share code, notes, and snippets.

@jhonata-menezes
Last active April 16, 2020 21:23
Show Gist options
  • Save jhonata-menezes/1bad154cc609ccce3737d4a187bef1d2 to your computer and use it in GitHub Desktop.
Save jhonata-menezes/1bad154cc609ccce3737d4a187bef1d2 to your computer and use it in GitHub Desktop.
Lista e Remove acl publico de buckets da AWS
import boto3
import requests
# docs - https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.BucketAcl.put
def s3_remove_acl_public(bucket_name: str):
bucket_acl = s3_acl(bucket_name)
bucket_acl.put(
ACL='private',
)
return bucket_acl
def s3_acl(bucket_name: str):
s3 = boto3.resource('s3')
return s3.BucketAcl(bucket_name)
def s3_get_acl(bucket_name: str):
bucket_acl = s3_acl(bucket_name)
return bucket_acl.grants
def is_public(bucket_name: str) -> bool:
response = requests.get(f'https://${bucket_name}.s3.amazonaws.com/', timeout=10)
return response.status_code == 200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment