Skip to content
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
23 changes: 21 additions & 2 deletions airflow/providers/amazon/aws/operators/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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".
Expand Down Expand Up @@ -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)
4 changes: 2 additions & 2 deletions docs/apache-airflow-providers-amazon/operators/lambda.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/always/test_project_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 9 additions & 9 deletions tests/providers/amazon/aws/operators/test_lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"}),
Expand All @@ -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",
Expand Down Expand Up @@ -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",
)
Expand All @@ -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",
)
Expand Down
4 changes: 2 additions & 2 deletions tests/system/providers/amazon/aws/example_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"}}}),
Expand Down