from typing import Dict
from typing import Any


def _create_key(payload: Dict[str, Any]) -> str:
  """Returns a string to be used as key for storing into Firestore.

  Args:
    payload: A JSON object with the information to use to generate the key.

  Returns:
    A string representing the key.
  Raises:
    KeyError: error indicating the necessary fields are not included into the
    message payload.
  """
  try:
    return "{}_{}_{}".format(payload["bq_output_table"], payload["uuid"],
                             str(payload["row"]["rowId"]))
  except KeyError:
    raise KeyError(
        "At least one of the following fields is missing in the message: uuid, bq_output_table, row"
    )