diff --git a/airflow/providers/amazon/aws/hooks/emr.py b/airflow/providers/amazon/aws/hooks/emr.py index d154452c3c56..f69ff90b35fa 100644 --- a/airflow/providers/amazon/aws/hooks/emr.py +++ b/airflow/providers/amazon/aws/hooks/emr.py @@ -72,11 +72,12 @@ def get_cluster_id_by_name(self, emr_cluster_name: str, cluster_states: list[str response_iterator = ( self.get_conn().get_paginator("list_clusters").paginate(ClusterStates=cluster_states) ) - matching_clusters = [] - for page in response_iterator: - matching_clusters.extend( - list(filter(lambda cluster: cluster["Name"] == emr_cluster_name, page["Clusters"])) - ) + matching_clusters = [ + cluster + for page in response_iterator + for cluster in page["Clusters"] + if cluster["Name"] == emr_cluster_name + ] if len(matching_clusters) == 1: cluster_id = matching_clusters[0]["Id"]