适用于按需节点us-west-1区域的AWS Elasticache价格表REST api

问题描述

我希望成本信息节点类型和每小时价格为JSON或CSV形式。 AWS是否已提供此信息作为REST端点?。

还是我必须刮擦下面的网页才能获得所需的信息?。

https://aws.amazon.com/elasticache/pricing/

解决方法

当然有一个API(它是AWS,几乎总是有一个API)。这是按地区获取定价的方法。

import requests
url = "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/elasticache/USD/current/elasticache.json?timestamp=1598870451424"
r = requests.get(url).json()

for region in r["regions"].values():
    for k,v in region.items():
        print(k)
        print(f"{v['Instance Type']} - {v['price']}")

这将产生:

OnDemand Cache Instance Standard cache m3.2xlarge Memcached Previous Generation
cache.m3.2xlarge - 0.8550000000
OnDemand Cache Instance Standard cache m3.2xlarge Redis Previous Generation
cache.m3.2xlarge - 0.8550000000
OnDemand Cache Instance Standard cache m3.large Memcached Previous Generation
cache.m3.large - 0.2180000000
...