Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Amazon S3 Connection Type #25980

Merged
merged 3 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions airflow/providers/amazon/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
Changelog
---------

.. warning::
In this version of provider Amazon S3 Connection (``conn_type="s3"``) removed due to the fact that it was always
an alias to :ref:`Amazon Web Services Connection <howto/connection:aws>` (``conn_type="aws"``).
In practice the only impact is you won't be able to ``test`` the connection in the web UI / API.
In order to restore ability to test connection you need to change connection type from **Amazon S3** (``conn_type="s3"``)
to **Amazon Web Services** (``conn_type="aws"``) manually.


5.1.0
.....

Expand Down
2 changes: 1 addition & 1 deletion airflow/providers/amazon/aws/hooks/base_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

.. seealso::
For more information on how to use this hook, take a look at the guide:
:ref:`howto/connection:AWSHook`
:ref:`howto/connection:aws`
"""
from __future__ import annotations

Expand Down
3 changes: 0 additions & 3 deletions airflow/providers/amazon/aws/hooks/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,6 @@ class S3Hook(AwsBaseHook):
:class:`~airflow.providers.amazon.aws.hooks.base_aws.AwsBaseHook`
"""

conn_type = 's3'
hook_name = 'Amazon S3'

def __init__(
self,
aws_conn_id: str | None = AwsBaseHook.default_conn_name,
Expand Down
14 changes: 12 additions & 2 deletions airflow/providers/amazon/aws/utils/connection_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,19 @@ def __post_init__(self, conn: Connection):
self.password = conn.password
self.extra_config = deepcopy(conn.extra_dejson)

if self.conn_type != "aws":
if self.conn_type.lower() == "s3":
dstandish marked this conversation as resolved.
Show resolved Hide resolved
warnings.warn(
f"{self.conn_repr} expected connection type 'aws', got {self.conn_type!r}.",
f"{self.conn_repr} has connection type 's3', "
"which has been replaced by connection type 'aws'. "
"Please update your connection to have `conn_type='aws'`.",
DeprecationWarning,
stacklevel=2,
)
elif self.conn_type != "aws":
warnings.warn(
f"{self.conn_repr} expected connection type 'aws', got {self.conn_type!r}. "
"This connection might not work correctly. "
dstandish marked this conversation as resolved.
Show resolved Hide resolved
"Please use Amazon Web Services Connection type.",
UserWarning,
stacklevel=2,
)
Expand Down
2 changes: 0 additions & 2 deletions airflow/providers/amazon/provider.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,6 @@ extra-links:
- airflow.providers.amazon.aws.links.logs.CloudWatchEventsLink

connection-types:
- hook-class-name: airflow.providers.amazon.aws.hooks.s3.S3Hook
connection-type: s3
Comment on lines -551 to -552
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also remove s3 from providers connection-type, otherwise webserver (provider manager?) warn about inconsistency and in UI appear two Amazon Web Services connections.

- hook-class-name: airflow.providers.amazon.aws.hooks.base_aws.AwsGenericHook
connection-type: aws
- hook-class-name: airflow.providers.amazon.aws.hooks.emr.EmrHook
Expand Down
2 changes: 1 addition & 1 deletion docs/apache-airflow-providers-amazon/connections/aws.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
specific language governing permissions and limitations
under the License.

.. _howto/connection:AWSHook:
.. _howto/connection:aws:

Amazon Web Services Connection
==============================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ To enable this feature, ``airflow.cfg`` must be configured as follows:
# id that provides access to the storage location.
remote_logging = True
remote_base_log_folder = s3://my-bucket/path/to/logs
remote_log_conn_id = MyS3Conn
remote_log_conn_id = my_s3_conn
# Use server-side encryption for logs stored in S3
encrypt_s3_logs = False

In the above example, Airflow will try to use ``S3Hook('MyS3Conn')``.
In the above example, Airflow will try to use ``S3Hook(aws_conn_id='my_s3_conn')``.

You can also use `LocalStack <https://localstack.cloud/>`_ to emulate Amazon S3 locally.
To configure it, you must additionally set the endpoint url to point to your local stack.
Expand Down
12 changes: 11 additions & 1 deletion tests/providers/amazon/aws/utils/test_connection_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,23 @@ def test_expected_aws_connection_type(self, conn_type):
wrap_conn = AwsConnectionWrapper(conn=mock_connection_factory(conn_type=conn_type))
assert wrap_conn.conn_type == "aws"

@pytest.mark.parametrize("conn_type", ["AWS", "boto3", "s3", "emr", "google", "google-cloud-platform"])
@pytest.mark.parametrize("conn_type", ["AWS", "boto3", "emr", "google", "google-cloud-platform"])
def test_unexpected_aws_connection_type(self, conn_type):
warning_message = f"expected connection type 'aws', got '{conn_type}'"
with pytest.warns(UserWarning, match=warning_message):
wrap_conn = AwsConnectionWrapper(conn=mock_connection_factory(conn_type=conn_type))
assert wrap_conn.conn_type == conn_type

@pytest.mark.parametrize("conn_type", ["s3", "S3"])
def test_deprecated_s3_connection_type(self, conn_type):
warning_message = (
r".* has connection type 's3', which has been replaced by connection type 'aws'\. "
r"Please update your connection to have `conn_type='aws'`."
)
with pytest.warns(DeprecationWarning, match=warning_message):
wrap_conn = AwsConnectionWrapper(conn=mock_connection_factory(conn_type=conn_type))
assert wrap_conn.conn_type == conn_type

@pytest.mark.parametrize("aws_session_token", [None, "mock-aws-session-token"])
@pytest.mark.parametrize("aws_secret_access_key", ["mock-aws-secret-access-key"])
@pytest.mark.parametrize("aws_access_key_id", ["mock-aws-access-key-id"])
Expand Down