【问题标题】:List all step information BOTO列出所有步骤信息 BOTO
【发布时间】:2020-08-26 02:58:53
【问题描述】:

我想知道是否有一种方法可以通过 boto 列出有关 emr 集群步骤的所有信息。我知道 aws cli 可以通过aws emr list-steps --cluster-id ID 做这样的事情。

这提供了该集群中所有步骤的所有信息;我想使用 python 和 boto 做同样的事情,但想知道 boto emr 中是否有一个选项可以列出所有信息(如 aws cli 打印)......目前我必须通过特定调用获取每个信息如:

    >>> conn.list_steps('j-2J699C85LW1R6').steps
    [<boto.emr.emrobject.StepSummary object at 0x107785ad0>,
     <boto.emr.emrobject.StepSummary object at 0x107798b90>,
     <boto.emr.emrobject.StepSummary object at 0x107798d90>,
     <boto.emr.emrobject.StepSummary object at 0x10778e650>,
     <boto.emr.emrobject.StepSummary object at 0x10778ea90>,]
    >>> conn.list_steps('j-2J699C85LW1R6').steps[0].id
    u's-2LLDFU54O55DJ'
    >>> conn.list_steps('j-2J699C85LW1R6').steps[0].status.state
    u'COMPLETED'

有很多像timeline.enddatetime, config.args,actiononfailure etc etc 这样的小参数,想知道是否有一个简单的命令可以在一次调用中检索所有这些信息以返回 json 或类似的东西。

【问题讨论】:

    标签: python json amazon-web-services boto


    【解决方案1】:

    您可以使用 describe_step 方法获取其他详细信息。

    http://boto.cloudhackers.com/en/latest/ref/emr.html

    describe_step(cluster_id, step_id)
    Describe an Elastic MapReduce step
    
    Parameters: 
    cluster_id (str) – The cluster id of interest
    step_id (str) – The step id of interest
    

    【讨论】:

      【解决方案2】:

      没有单一的调用,但您可以获取步骤列表,然后遍历它们,在每个步骤上调用 describe_step。以下是我在 GitHub 上的完整示例中的几个函数。

      def list_steps(cluster_id, emr_client):
          """
          Gets a list of steps for the specified cluster. In this example, all steps are
          returned, including completed and failed steps.
          :param cluster_id: The ID of the cluster.
          :param emr_client: The Boto3 EMR client object.
          :return: The list of steps for the specified cluster.
          """
          try:
              response = emr_client.list_steps(ClusterId=cluster_id)
              steps = response['Steps']
              logger.info("Got %s steps for cluster %s.", len(steps), cluster_id)
          except ClientError:
              logger.exception("Couldn't get steps for cluster %s.", cluster_id)
              raise
          else:
              return steps
      
      
      def describe_step(cluster_id, step_id, emr_client):
          """
          Gets detailed information about the specified step, including the current state of
          the step.
          :param cluster_id: The ID of the cluster.
          :param step_id: The ID of the step.
          :param emr_client: The Boto3 EMR client object.
          :return: The retrieved information about the specified step.
          """
          try:
              response = emr_client.describe_step(ClusterId=cluster_id, StepId=step_id)
              step = response['Step']
              logger.info("Got data for step %s.", step_id)
          except ClientError:
              logger.exception("Couldn't get data for step %s.", step_id)
              raise
          else:
              return step
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-11-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-05-25
        相关资源
        最近更新 更多