【问题标题】:Unable to find Minimum/Maximum task value for ECS找不到 ECS 的最小/最大任务值
【发布时间】:2022-01-19 20:13:01
【问题描述】:

我正在使用 aws boto3 lib 并尝试检索某些值。 我首先检索所有集群列表,然后获取特定服务,然后为它们调用 describe-service。 但我无法检索显示在 Auto Scaling 选项卡下的 AWS ECS 控制台页面上的服务的最小任务和最大任务两个字段。

有人知道如何从中获取这些值吗?

【问题讨论】:

    标签: amazon-web-services boto3 amazon-ecs


    【解决方案1】:

    ECS 控制台隐藏了这一事实,但这些实际上是在 Application AutoScaling 配置中,而不是 ECS 配置中。我相信你需要在ApplicationAutoScaling 中调用describe_scalable_targets 来获取这些值。

    【讨论】:

      【解决方案2】:

      感谢马克 B 的帮助。 你是对的,我知道 aws ecs 服务必须注册自动缩放服务,这是一项单独的服务。我现在提供示例 cli 和 python 代码来检索这些值。

      aws ecs describe-services --cluster MAGIC-Bonus-Wrappers --services service-name
      aws application-autoscaling describe-scalable-targets --service-namespace ecs --resource-ids service/cluster-name/service-name
      

      Python 代码:

      client = session.client('application-autoscaling')
      response = client.describe_scalable_targets(
          ServiceNamespace='ecs',
          ResourceIds=[serviceId])
          
          def_val = -1, -1
          if "ScalableTargets" in response and len(response['ScalableTargets']) > 0 :
              target = response['ScalableTargets'][0]
              if 'MinCapacity' in target and 'MaxCapacity' in target:
                  return target['MinCapacity'], target['MaxCapacity']
              else:
                  return def_val
      

      【讨论】:

        猜你喜欢
        • 2019-03-28
        • 2019-04-05
        • 2012-06-21
        • 1970-01-01
        • 1970-01-01
        • 2012-02-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多