簡體   English   中英

如何獲取 AWS EMR 的實例列表?

[英]How to get the list of instances for AWS EMR?

為什么 EC2 的列表與 EMR 列表不同?

EC2: https : //aws.amazon.com/ec2/spot/pricing/

EMR: https : //aws.amazon.com/emr/pricing/

為什么不是所有類型的 EC2 實例都可用於 EMR? 如何獲得這份特別名單?

如果您的問題與亞馬遜控制台無關
(那么它肯定會被關閉為題外話):

作為編程解決方案,您看起來像這樣:(使用 python boto3

import boto3
client = boto3.client('emr')
for instance in client.list_instances():
  print("Instance[%s] %s"%(instance.id, instance.name))

這就是我使用的,雖然我不是 100% 確定它是准確的(因為我找不到文檔來支持我的一些選擇(-BoxUsage 等))。

值得查看來自 AWS 的響應,以找出定價客戶端響應中不同字段的不同值。

使用以下命令獲取響應列表:

   default_profile = boto3.session.Session(profile_name='default')
    # Only us-east-1 has the pricing API
    # - https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/pricing.html
    pricing_client = default_profile.client('pricing', region_name='us-east-1')
    service_name = 'ElasticMapReduce'
    product_filters = [
        {'Type': 'TERM_MATCH', 'Field': 'location', 'Value': aws_region_name}
    ]
    response = pricing_client.get_products(
        ServiceCode=service_name,
        Filters=product_filters,
        MaxResults=100
    )
    response_list.append(response)

    num_prices = 100
    while 'NextToken' in response:
       # re-query to get next page

獲得響應列表后,您可以過濾掉實際的實例信息:

  emr_prices = {}
  for response in response_list:
      for price_info_str in response['PriceList']:
          price_obj = json.loads(price_info_str)
          attributes = price_obj['product']['attributes']

          # Skip pricing info that doesn't specify a (EC2) instance type
          if 'instanceType' not in attributes:
              continue
          inst_type = attributes['instanceType']

          # AFAIK, Only usagetype attributes that contain the string '-BoxUsage' are the ones that contain the prices that we would use (empirical research)
          # Other examples of values are <REGION-CODE>-M3BoxUsage, <REGION-CODE>-M5BoxUsage, <REGION-CODE>-M7BoxUsage (no clue what that means.. )
          if '-BoxUsage' not in attributes['usagetype']:
              continue

          if 'OnDemand' not in price_obj['terms']:
              continue

          on_demand_info = price_obj['terms']['OnDemand']
          price_dim = list(list(on_demand_info.values())[0]['priceDimensions'].values())[0]
          emr_price = Decimal(price_dim['pricePerUnit']['USD'])

          emr_prices[inst_type] = emr_price

實際上,從 boto3 文檔中弄清楚這一點很簡單。 特別是get_products文檔。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM