如何使用boto3查询AWS实例存储卷的IOPS规格?
获取EC2实例存储卷IOPS规格的正确方式
describe_instance_types API确实不会返回实例存储卷的IOPS数据,该接口的InstanceStoreInfo字段仅包含存储卷的数量、单卷大小、存储类型等基础信息,示例返回结构如下:
"InstanceStoreInfo": { "TotalSizeInGB": 1920, "Disks": [ { "SizeInGB": 960, "Type": "ssd" }, { "SizeInGB": 960, "Type": "ssd" } ], "Supported": true }
要获取实例存储的IOPS规格,需要使用AWS Price List API——实例存储的性能参数被归类在产品元数据中,而非EC2核心实例信息接口里。以下是具体的boto3实现代码:
import boto3 import json def fetch_instance_store_iops(instance_type): # Price List API仅在us-east-1区域可用 pricing_client = boto3.client('pricing', region_name='us-east-1') response = pricing_client.get_products( ServiceCode='AmazonEC2', Filters=[ {'Type': 'TERM_MATCH', 'Field': 'instanceType', 'Value': instance_type}, {'Type': 'TERM_MATCH', 'Field': 'location', 'Value': 'US East (N. Virginia)'} ], FormatVersion='aws_v1' ) for product_entry in response['PriceList']: product_details = json.loads(product_entry) attrs = product_details['product']['attributes'] if 'instanceStorageIops' in attrs: return attrs['instanceStorageIops'] return "IOPS数据未找到" # 调用示例 print(fetch_instance_store_iops('im4gn.4xlarge'))
注意事项
- Price List API仅部署在
us-east-1区域,调用时必须指定该区域。 - 部分实例类型的IOPS可能返回范围值(如
10000-20000),需根据业务需求处理格式。 - 若需要其他区域的实例数据,可修改
location参数(如EU (Ireland)对应eu-west-1),实例存储性能参数通常在全球区域保持一致。
内容的提问来源于stack exchange,提问作者Craig Nelson
相关产品推荐
相关产品推荐

