Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get bucket policy using Airflow s3 hook

I would like to find out what is the bucket policy programmatically using Airflow S3 Hook, for a specific S3 bucket.
boto3 has get_bucket_policy method, but S3 hook doesn’t seem to have it.
Is there any way to do that using the S3 hook?
Thanks!

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You get an instance of boto3.S3.Bucket calling S3Hook.get_bucket instance method.

This instance has a Policy method that can be used to access to policy resource associated to the bucket.

from airflow.providers.amazon.aws.hooks.s3 import S3Hook

s3_hook = S3Hook(aws_conn_id='aws_conn_id')
bucket = s3_hook.get_bucket('your-bucket-name')
policy_resource = bucket.Policy()

policy_json = policy_resource.policy
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading