要获取AWS Elasticache云服务us-west-1地区按需节点的价格列表,可以使用AWS Pricing API。以下是一个使用Python的代码示例:
import requests
import json
def get_elasticache_price_list():
region = 'us-west-1'
service_code = 'AmazonElastiCache'
url = f"https://pricing.us-west-1.amazonaws.com/offers/v1.0/aws/{service_code}/current/index.json"
response = requests.get(url)
data = json.loads(response.text)
products = data['products']
terms = data['terms']['OnDemand']
for sku, product in products.items():
if 'attributes' in product and 'location' in product['attributes'] and product['attributes']['location'] == region:
for term in terms[sku].values():
for price_dimension in term['priceDimensions'].values():
price_per_hour = price_dimension['pricePerUnit']['USD']
print(f"SKU: {sku}")
print(f"Price per hour: {price_per_hour}")
print()
get_elasticache_price_list()
这段代码首先构建了请求的URL,然后使用requests
库发送GET请求获取响应数据。接着通过解析JSON数据,获取每个产品的SKU、价格信息,并打印出来。
需要注意的是,该代码示例是基于AWS Pricing API的当前版本,如果API有任何更改,代码可能需要做相应的调整。