class_docstr: Interact with Amazon Elastic MapReduce Service (EMR).
  
  Provide thick wrapper around :external+boto3:py:class:`boto3.client("emr") <EMR.Client>`.
  
  :param emr_conn_id: :ref:`Amazon Elastic MapReduce Connection <howto/connection:emr>`.
      This attribute is only necessary when using
      the :meth:`airflow.providers.amazon.aws.hooks.emr.EmrHook.create_job_flow`.
  
  Additional arguments (such as ``aws_conn_id``) may be specified and
  are passed down to the underlying AwsBaseHook.
  
  .. seealso::
      :class:`~airflow.providers.amazon.aws.hooks.base_aws.AwsBaseHook`
class_docstr_tok: ["Interact","with","Amazon","Elastic","MapReduce","Service","(","EMR",")",".","Provide","thick","wrapper","around",":","external+boto3",":","py",":","class",":","`","boto3.client","(","``","emr","''",")","<","EMR.Client",">","`",".",":","param","emr_conn_id",":",":","ref",":","`","Amazon","Elastic","MapReduce","Connection","<","howto\/connection",":","emr",">","`",".","This","attribute","is","only","necessary","when","using","the",":","meth",":","`","airflow.providers.amazon.aws.hooks.emr.EmrHook.create_job_flow","`",".","Additional","arguments","(","such","as","``","aws_conn_id","``",")","may","be","specified","and","are","passed","down","to","the","underlying","AwsBaseHook",".","..","seealso",":",":",":","class",":","`","~airflow.providers.amazon.aws.hooks.base_aws.AwsBaseHook","`"]
docstr: Fetch id of EMR cluster with given name and (optional) states; returns only if single id is found.
  
  .. seealso::
      - :external+boto3:py:meth:`EMR.Client.list_clusters`
  
  :param emr_cluster_name: Name of a cluster to find
  :param cluster_states: State(s) of cluster to find
  :return: id of the EMR cluster
docstr_tok: ["Fetch","id","of","EMR","cluster","with","given","name","and","(","optional",")","states",";","returns","only","if","single","id","is","found",".","..","seealso",":",":","-",":","external+boto3",":","py",":","meth",":","`","EMR.Client.list_clusters","`",":","param","emr_cluster_name",":","Name","of","a","cluster","to","find",":","param","cluster_states",":","State","(","s",")","of","cluster","to","find",":","return",":","id","of","the","EMR","cluster"]
code: def get_cluster_id_by_name(
      self, emr_cluster_name: str, cluster_states: list[str]
  ) -> str | None:
      """
      Fetch id of EMR cluster with given name and (optional) states; returns only if single id is found.
  
      .. seealso::
          - :external+boto3:py:meth:`EMR.Client.list_clusters`
  
      :param emr_cluster_name: Name of a cluster to find
      :param cluster_states: State(s) of cluster to find
      :return: id of the EMR cluster
      """
      response_iterator = (
          self.get_conn()
          .get_paginator("list_clusters")
          .paginate(ClusterStates=cluster_states)
      )
      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"]
          self.log.info(
              "Found cluster name = %s id = %s",
              emr_cluster_name,
              cluster_id,
          )
          return cluster_id
      elif len(matching_clusters) > 1:
          raise AirflowException(
              f"More than one cluster found for name {emr_cluster_name}"
          )
      else:
          self.log.info(
              "No cluster found for name %s", emr_cluster_name
          )
          return None
  
imports: from __future__ import annotations
  import json
  import time
  import warnings
  from typing import Any
  from botocore.exceptions import ClientError
  from airflow.exceptions import AirflowException, AirflowNotFoundException
  from airflow.providers.amazon.aws.hooks.base_aws import AwsBaseHook
  from airflow.providers.amazon.aws.utils.waiter_with_logging import wait
label_desc: Use image node_id 2 for calling the EmrHook obj's underlying member method code with example usage: obj.get_cluster_id_by_name(emr_cluster_name, cluster_states) and returns: cluster_id, None