跳转到主要内容

AWS定价的SDK

项目描述

========== awspricing

用于操作AWS价格列表查询API的Python库 AWS Price List Query API <https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/pricing.html>_.

从2.0.0版本开始,awspricing使用boto3价格列表查询API。这需要价格列表查询API IAM角色:https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/billing-permissions-ref.html#example-policy-pe-api

2.0.0版本之前的版本使用了AWS价格报价文件。

功能

  • 特定服务的辅助工具(目前仅限于EC2和RDS)
  • 本地缓存支持

安装

.. code-block:: sh

$ pip install awspricing

使用

.. code-block:: python

import awspricing

ec2_offer = awspricing.offer('AmazonEC2')

ec2_offer.search_skus(
  instance_type='c4.large',
  location='US East (N. Virginia)',
  operating_system='Linux',
)  # {'4C7N4APU9GEUZ6H6', 'MBQPYDJSY3BY84BH', 'MDKVAJXMJGZFDJUE'}

ec2_offer.reserved_hourly(
  'c4.xlarge',
  operating_system='Linux',
  lease_contract_length='3yr',
  offering_class='convertible',
  purchase_option='Partial Upfront',
  region='us-east-1'
)  # 0.10845205479452055

rds_offer = awspricing.offer('AmazonRDS')

rds_offer.search_skus(
  instance_type='db.m4.large',
  location='US East (N. Virginia)',
  database_engine='MySQL',
  license_model='No license required',
  deployment_option='Multi-AZ'
) # {'QPZNR6MYN432XTPU'}

rds_offer.ondemand_hourly(
  'db.m4.large',
  'MySQL',
  license_model='No license required',
  deployment_option='Multi-AZ',
  region='us-east-1'
) # 0.35

..

注意 : AWS以json格式提供定价列表,不保证格式不会更改。如果AWS的格式更改导致破坏性更改,则可以使用以下缓解措施,代价是“过时的”定价。

.. code-block:: python

import awspricing

# For finding EC2 price list versions see script below or download https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/index.json
ec2_offer_old = awspricing.offer('AmazonEC2', version='some_other_version')

# For finding RDS price list versions see script below or download https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonRDS/index.json
rds_offer_old = awspricing.offer('AmazonRDS', version='some_other_version')

.. code-block:: sh

$ # EC2
$ curl https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/index.json | python -m json.tool

$ # RDS
$ curl https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonRDS/index.json | python -m json.tool

配置

缓存


Cache can be configured via the following environment variables:

``AWSPRICING_USE_CACHE``: Whether to use a simple file-based cache. Valid values are ``0|1``. Defaults to ``0`` (false).

``AWSPRICING_CACHE_PATH``: Prefix to write cache files. Defaults to ``/tmp/awspricing``.

``AWSPRICING_CACHE_MINUTES``: Number of minutes to keep cache for. Defaults to ``1440`` (1 day).


Developing
----------

Environment setup

运行以下命令(最好在虚拟环境)来设置您的环境

.. code-block:: sh python setup.py develop pip install -r test-requirements.txt

运行单元测试


Simply run `make test` after environment setup to run unit tests.

Running mypy (type checker)

可以使用以下命令运行类型检查。请注意,mypy需要python3解释器。

.. code-block:: sh

pip install mypy
make test_mypy

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分发

awspricing-2.0.3.tar.gz (9.2 kB 查看哈希值)

上传时间

支持者

AWSAWS云计算和安全赞助商DatadogDatadog监控FastlyFastlyCDNGoogleGoogle下载分析MicrosoftMicrosoftPSF赞助商PingdomPingdom监控SentrySentry错误记录StatusPageStatusPage状态页面