首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何获取AWS EMR的实例列表?

如何获取AWS EMR的实例列表?
EN

Stack Overflow用户
提问于 2018-05-21 03:59:28
回答 2查看 947关注 0票数 1

为什么EC2的列表与电子病历列表不同?

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

电子病历:https://aws.amazon.com/emr/pricing/

为什么EC2中的所有类型的实例都不能用于电子病历?如何获得这个特殊的列表?

EN

回答 2

Stack Overflow用户

发布于 2018-05-21 21:44:37

如果您的问题不是关于amazon控制台的

(然后它肯定会作为off-topic关闭):

作为一个编程解决方案,您看起来像这样:(使用python )

代码语言:javascript
运行
复制
import boto3
client = boto3.client('emr')
for instance in client.list_instances():
  print("Instance[%s] %s"%(instance.id, instance.name))
票数 1
EN

Stack Overflow用户

发布于 2020-02-21 21:33:25

这就是我使用的,尽管我不能100%确定它的准确性(因为我找不到文档来支持我的一些选择(-BoxUsage等))。

为了找出定价客户端响应中不同字段的不同值,有必要查看AWS的响应。

使用以下命令获取响应列表:

代码语言:javascript
运行
复制
   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

一旦你得到了响应列表,你就可以过滤出实际的实例信息:

代码语言:javascript
运行
复制
  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文档。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50438888

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档