o-nikolas opened a new pull request, #25805: URL: https://github.com/apache/airflow/pull/25805
This PR was brought about by the confusion caused by the current code (see thread [here](https://apache-airflow.slack.com/archives/CQ9QHSFQX/p1660782744639849?thread_ts=1660781402.798729&cid=CQ9QHSFQX)). `S3Hook.check_for_bucket()` method uses the boto3 s3 client method `head_bucket` ([docs](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Client.head_bucket)) to check for bucket existence. This client method does not work like most boto3 APIs, it only returns a small subset of error codes with very little context. Manual examples/testing of the updated code: ```python In [1]: from airflow.providers.amazon.aws.hooks.s3 import S3Hook <omitted airflow init logging> In [2]: s3hook = S3Hook() In [3]: s3hook.check_for_bucket('test') # Exists but not owned by this account [2022-08-18 14:01:15,677] {s3.py:215} ERROR - Access to bucket "test" is forbidden or there was an error with the request [2022-08-18 14:01:15,677] {s3.py:218} ERROR - An error occurred (403) when calling the HeadBucket operation: Forbidden Out[3]: False In [4]: s3hook.check_for_bucket('asdfasdfgfdsagfdsfaasdlkjlkdsajflsad') # Does not exist [2022-08-18 14:01:39,237] {s3.py:213} ERROR - Bucket "asdfasdfgfdsagfdsfaasdlkjlkdsajflsad" does not exist Out[4]: False In [5]: s3hook.check_for_bucket('env6a7fbbff-athena-bucket') # Exists in the account Out[5]: True ``` <!-- Thank you for contributing! Please make sure that your code changes are covered with tests. And in case of new features or big changes remember to adjust the documentation. Feel free to ping committers for the review! In case of an existing issue, reference it using one of the following: closes: #ISSUE related: #ISSUE How to write a good git commit message: http://chris.beams.io/posts/git-commit/ --> --- **^ Add meaningful description above** Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#pull-request-guidelines)** for more information. In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed. In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x). In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
