From fe4e38bf7c7957f7df457e2131cb9de42581c3da Mon Sep 17 00:00:00 2001
From: Elad Kalif <45845474+eladkal@users.noreply.github.com>
Date: Fri, 24 Feb 2023 21:04:08 +0200
Subject: [PATCH] Standardize AWS lambda naming closes:
 https://github.com/apache/airflow/issues/29677

---
 .../amazon/aws/operators/lambda_function.py   | 23 +++++++++++++++++--
 .../operators/lambda.rst                      |  4 ++--
 tests/always/test_project_structure.py        |  4 ++++
 .../aws/operators/test_lambda_function.py     | 18 +++++++--------
 .../providers/amazon/aws/example_lambda.py    |  4 ++--
 5 files changed, 38 insertions(+), 15 deletions(-)

diff --git a/airflow/providers/amazon/aws/operators/lambda_function.py b/airflow/providers/amazon/aws/operators/lambda_function.py
index c53fd821327df..345e649419220 100644
--- a/airflow/providers/amazon/aws/operators/lambda_function.py
+++ b/airflow/providers/amazon/aws/operators/lambda_function.py
@@ -18,6 +18,7 @@
 from __future__ import annotations
 
 import json
+import warnings
 from typing import TYPE_CHECKING, Sequence
 
 from airflow.compat.functools import cached_property
@@ -118,7 +119,7 @@ def execute(self, context: Context):
         return response.get("FunctionArn")
 
 
-class AwsLambdaInvokeFunctionOperator(BaseOperator):
+class LambdaInvokeFunctionOperator(BaseOperator):
     """
     Invokes an AWS Lambda function. You can invoke a function synchronously (and wait for the response),
     or asynchronously.
@@ -127,7 +128,7 @@ class AwsLambdaInvokeFunctionOperator(BaseOperator):
 
     .. seealso::
         For more information on how to use this operator, take a look at the guide:
-        :ref:`howto/operator:AwsLambdaInvokeFunctionOperator`
+        :ref:`howto/operator:LambdaInvokeFunctionOperator`
 
     :param function_name: The name of the AWS Lambda function, version, or alias.
     :param log_type: Set to Tail to include the execution log in the response. Otherwise, set to "None".
@@ -194,3 +195,21 @@ def execute(self, context: Context):
             )
         self.log.info("Lambda function invocation succeeded: %r", response.get("ResponseMetadata"))
         return payload
+
+
+class AwsLambdaInvokeFunctionOperator(LambdaInvokeFunctionOperator):
+    """
+    This class is deprecated.
+    Please use
+    :class:`airflow.providers.amazon.aws.operators.lambda_function.LambdaInvokeFunctionOperator`.
+    """
+
+    def __init__(self, *args, **kwargs):
+        warnings.warn(
+            "This class is deprecated."
+            "Please use"
+            "`airflow.providers.amazon.aws.operators.lambda_function.LambdaInvokeFunctionOperator`.",
+            DeprecationWarning,
+            stacklevel=2,
+        )
+        super().__init__(*args, **kwargs)
diff --git a/docs/apache-airflow-providers-amazon/operators/lambda.rst b/docs/apache-airflow-providers-amazon/operators/lambda.rst
index eb161d4783be7..2ec14eb5ba4b2 100644
--- a/docs/apache-airflow-providers-amazon/operators/lambda.rst
+++ b/docs/apache-airflow-providers-amazon/operators/lambda.rst
@@ -47,13 +47,13 @@ To create an AWS lambda function you can use
     :start-after: [START howto_operator_create_lambda_function]
     :end-before: [END howto_operator_create_lambda_function]
 
-.. _howto/operator:AwsLambdaInvokeFunctionOperator:
+.. _howto/operator:LambdaInvokeFunctionOperator:
 
 Invoke an AWS Lambda function
 =============================
 
 To invoke an AWS lambda function you can use
-:class:`~airflow.providers.amazon.aws.operators.lambda_function.AwsLambdaInvokeFunctionOperator`.
+:class:`~airflow.providers.amazon.aws.operators.lambda_function.LambdaInvokeFunctionOperator`.
 
 .. exampleinclude:: /../../tests/system/providers/amazon/aws/example_lambda.py
     :language: python
diff --git a/tests/always/test_project_structure.py b/tests/always/test_project_structure.py
index 479e68fcbcb46..523f81663343f 100644
--- a/tests/always/test_project_structure.py
+++ b/tests/always/test_project_structure.py
@@ -403,6 +403,10 @@ class TestAmazonProviderProjectStructure(ExampleCoverageTest):
         "airflow.providers.amazon.aws.sensors.emr.EmrStepSensor",
     }
 
+    DEPRECATED_CLASSES = {
+        "airflow.providers.amazon.aws.operators.lambda_function.AwsLambdaInvokeFunctionOperator",
+    }
+
 
 class TestElasticsearchProviderProjectStructure(ExampleCoverageTest):
     PROVIDER = "elasticsearch"
diff --git a/tests/providers/amazon/aws/operators/test_lambda_function.py b/tests/providers/amazon/aws/operators/test_lambda_function.py
index 28b69564e424b..6f1d98e8ac8bc 100644
--- a/tests/providers/amazon/aws/operators/test_lambda_function.py
+++ b/tests/providers/amazon/aws/operators/test_lambda_function.py
@@ -25,8 +25,8 @@
 
 from airflow.providers.amazon.aws.hooks.lambda_function import LambdaHook
 from airflow.providers.amazon.aws.operators.lambda_function import (
-    AwsLambdaInvokeFunctionOperator,
     LambdaCreateFunctionOperator,
+    LambdaInvokeFunctionOperator,
 )
 
 FUNCTION_NAME = "function_name"
@@ -69,9 +69,9 @@ def test_create_lambda_with_wait_for_completion(self, mock_hook_conn, mock_hook_
         mock_hook_conn.get_waiter.assert_called_once_with("function_active_v2")
 
 
-class TestAwsLambdaInvokeFunctionOperator:
+class TestLambdaInvokeFunctionOperator:
     def test_init(self):
-        lambda_operator = AwsLambdaInvokeFunctionOperator(
+        lambda_operator = LambdaInvokeFunctionOperator(
             task_id="test",
             function_name="test",
             payload=json.dumps({"TestInput": "Testdata"}),
@@ -84,9 +84,9 @@ def test_init(self):
         assert lambda_operator.log_type == "None"
         assert lambda_operator.aws_conn_id == "aws_conn_test"
 
-    @patch.object(AwsLambdaInvokeFunctionOperator, "hook", new_callable=mock.PropertyMock)
+    @patch.object(LambdaInvokeFunctionOperator, "hook", new_callable=mock.PropertyMock)
     def test_invoke_lambda(self, hook_mock):
-        operator = AwsLambdaInvokeFunctionOperator(
+        operator = LambdaInvokeFunctionOperator(
             task_id="task_test",
             function_name="a",
             invocation_type="b",
@@ -115,9 +115,9 @@ def test_invoke_lambda(self, hook_mock):
             qualifier="f",
         )
 
-    @patch.object(AwsLambdaInvokeFunctionOperator, "hook", new_callable=mock.PropertyMock)
+    @patch.object(LambdaInvokeFunctionOperator, "hook", new_callable=mock.PropertyMock)
     def test_invoke_lambda_bad_http_code(self, hook_mock):
-        operator = AwsLambdaInvokeFunctionOperator(
+        operator = LambdaInvokeFunctionOperator(
             task_id="task_test",
             function_name="a",
         )
@@ -126,9 +126,9 @@ def test_invoke_lambda_bad_http_code(self, hook_mock):
         with pytest.raises(ValueError):
             operator.execute(None)
 
-    @patch.object(AwsLambdaInvokeFunctionOperator, "hook", new_callable=mock.PropertyMock)
+    @patch.object(LambdaInvokeFunctionOperator, "hook", new_callable=mock.PropertyMock)
     def test_invoke_lambda_function_error(self, hook_mock):
-        operator = AwsLambdaInvokeFunctionOperator(
+        operator = LambdaInvokeFunctionOperator(
             task_id="task_test",
             function_name="a",
         )
diff --git a/tests/system/providers/amazon/aws/example_lambda.py b/tests/system/providers/amazon/aws/example_lambda.py
index 505681f6b2332..b4951799c8b08 100644
--- a/tests/system/providers/amazon/aws/example_lambda.py
+++ b/tests/system/providers/amazon/aws/example_lambda.py
@@ -27,8 +27,8 @@
 from airflow.decorators import task
 from airflow.models.baseoperator import chain
 from airflow.providers.amazon.aws.operators.lambda_function import (
-    AwsLambdaInvokeFunctionOperator,
     LambdaCreateFunctionOperator,
+    LambdaInvokeFunctionOperator,
 )
 from airflow.providers.amazon.aws.sensors.lambda_function import LambdaFunctionStateSensor
 from airflow.utils.trigger_rule import TriggerRule
@@ -100,7 +100,7 @@ def delete_lambda(function_name: str):
     wait_lambda_function_state.poke_interval = 1
 
     # [START howto_operator_invoke_lambda_function]
-    invoke_lambda_function = AwsLambdaInvokeFunctionOperator(
+    invoke_lambda_function = LambdaInvokeFunctionOperator(
         task_id="invoke_lambda_function",
         function_name=lambda_function_name,
         payload=json.dumps({"SampleEvent": {"SampleData": {"Name": "XYZ", "DoB": "1993-01-01"}}}),
