eladkal commented on code in PR #32498:
URL: https://github.com/apache/airflow/pull/32498#discussion_r1258692161


##########
airflow/providers/amazon/aws/operators/eventbridge.py:
##########
@@ -0,0 +1,87 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+from typing import Sequence
+
+from airflow import AirflowException
+from airflow.decorators.base import cached_property

Review Comment:
   I think this should be
   `from functools import cached_property`



##########
airflow/providers/amazon/aws/operators/eventbridge.py:
##########
@@ -0,0 +1,87 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+from typing import Sequence
+
+from airflow import AirflowException
+from airflow.decorators.base import cached_property
+from airflow.models import BaseOperator
+from airflow.providers.amazon.aws.hooks.eventbridge import EventBridgeHook
+from airflow.providers.amazon.aws.utils import trim_none_values
+from airflow.utils.context import Context

Review Comment:
   Shouldn't this be under `TYPE_CHECKING` ?



##########
airflow/providers/amazon/aws/operators/eventbridge.py:
##########
@@ -0,0 +1,87 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+from typing import Sequence
+
+from airflow import AirflowException
+from airflow.decorators.base import cached_property
+from airflow.models import BaseOperator
+from airflow.providers.amazon.aws.hooks.eventbridge import EventBridgeHook
+from airflow.providers.amazon.aws.utils import trim_none_values
+from airflow.utils.context import Context
+
+
+class EventBridgePutEventsOperator(BaseOperator):
+    """
+    Put Events onto Amazon EventBridge.
+
+    :param entries: the list of events to be put onto EventBridge, each event 
is a dict (required)
+    :param endpoint_id: the URL subdomain of the endpoint
+    :param aws_conn_id: the AWS connection to use
+    :param region_name: the region where events are to be sent
+
+    """
+
+    template_fields: Sequence[str] = ("entries", "endpoint_id", "aws_conn_id", 
"region_name")
+
+    def __init__(
+        self,
+        *,
+        entries: list[dict],
+        endpoint_id: str | None = None,
+        aws_conn_id: str = "aws_default",
+        region_name: str | None = None,
+        **kwargs,
+    ):
+        super().__init__(**kwargs)
+        self.entries = entries
+        self.endpoint_id = endpoint_id
+        self.aws_conn_id = aws_conn_id
+        self.region_name = region_name
+
+    @cached_property
+    def hook(self) -> EventBridgeHook:
+        """Create and return an EventBridgeHook."""
+        return EventBridgeHook(aws_conn_id=self.aws_conn_id, 
region_name=self.region_name)
+
+    def execute(self, context: Context):
+
+        response = self.hook.conn.put_events(
+            **trim_none_values(
+                {
+                    "Entries": self.entries,
+                    "EndpointId": self.endpoint_id,
+                }
+            )
+        )
+
+        self.log.info("Sent %d events to EventBridge.", len(self.entries))
+
+        # If events have failed, log those error codes and messages to 
console, and raise an exception.
+
+        if "FailedEntryCount" in response:
+            self.log.error("Some events have failed to send.")
+            for event in response["Entries"]:
+                if "ErrorCode" in event:
+                    self.log.error(event)

Review Comment:
   Shouldn't we just dump the response to the log?
   Why do we need to parse it?



-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to