Name | awscost JSON |
Version |
0.3.2
JSON |
| download |
home_page | None |
Summary | Command Line utility for cost of aws. |
upload_time | 2024-07-07 12:33:10 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.7 |
license | None |
keywords |
awscost
tool
aws
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# awscost
[![PyPI version](https://badge.fury.io/py/awscost.svg)](https://badge.fury.io/py/awscost)
[![Build Status](https://github.com/toyama0919/awscost/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/toyama0919/awscost/actions/workflows/ci.yml)
Command Line utility for Provides aws cost very easy to see.
Supports python 3.7 or later.
## Install
```bash
$ pip install awscost
```
## Examples
### show cost
show cost latest 5 months.
```bash
$ awscost
key 2019-07 2019-08 2019-09 2019-10 2019-11 2019-12
-------------------------------------- --------- --------- --------- --------- --------- ---------
Total 348.34 97.4 98.46 106.47 67.25 7.84
EC2 - Other 34.28 34.28 33.2 34.28 33.63 3.01
Amazon Elastic Compute Cloud - Compute 17.11 17.11 16.56 17.11 17.13 1.47
AWS Cost Explorer 0.56 1.44
Tax 25.8 7.22 7.27 9.72 6.12 0.69
AWS CloudTrail 3.29 3.21 4.15 5.57 4.44 0.61
AWS Key Management Service 0 0 2.8 4 4 0.35
AmazonCloudWatch 1.5 0.01 0 0 0.88 0.11
Amazon Route 53 0.1 0.1 0.1 0.1 0.1 0.1
Amazon Simple Storage Service 0.25 0.24 0.27 0.45 0.4 0.05
AWS Lambda 0 0 0 0 0 0
Amazon DynamoDB 0 0 0 0 0
Amazon Elastic File System 0 0 0 0 0 0
Amazon SageMaker 266 35.22 34.11 35.22 0
Amazon Simple Notification Service 0 0 0
Amazon Polly 0
Amazon Simple Queue Service 0
```
show cost latest 3 days, group by SERVICE and operation.
```bash
$ awscost -g DAILY -p 3 -d SERVICE -d OPERATION
key 2019-12-01 2019-12-02 2019-12-03
------------------------------------------------------------ ------------ ------------ ------------
Total 2.87 2.1 2.87
GetCostAndUsage,AWS Cost Explorer 0.02 1.42
NatGateway,EC2 - Other 1.08 1.08 0.77
RunInstances,Amazon Elastic Compute Cloud - Compute 0.55 0.55 0.37
None,AWS CloudTrail 0.22 0.22 0.17
Unknown,AWS Key Management Service 0.13 0.13 0.09
Unknown,AmazonCloudWatch 0.04 0.04 0.03
CreateVolume-Gp2,EC2 - Other 0.03 0.03 0.01
PutObject,Amazon Simple Storage Service 0.02 0.02 0.01
NoOperation,Tax 0.25
...
```
### support dimensions
* AZ
* INSTANCE_TYPE
* LINKED_ACCOUNT
* OPERATION
* PURCHASE_TYPE
* SERVICE
* USAGE_TYPE
* PLATFORM
* TENANCY
* RECORD_TYPE
* LEGAL_ENTITY_NAME
* DEPLOYMENT_OPTION
* DATABASE_ENGINE
* CACHE_ENGINE
* INSTANCE_TYPE_FAMILY
* REGION
* BILLING_ENTITY
* RESERVATION_ID
* SAVINGS_PLANS_TYPE
* SAVINGS_PLAN_ARN
* OPERATING_SYSTEM
see. https://docs.aws.amazon.com/aws-cost-management/latest/APIReference/API_GetDimensionValues.html
### support filter
```bash
awscost --filter '{
"Not": {
"Dimensions": {
"Key": "RECORD_TYPE",
"Values": ["Credit", "Refund", "Upfront"]
}
}
}'
```
## config file($HOME/.awscost)
```yaml:$HOME/.awscost
default:
metrics: AmortizedCost
filter:
Dimensions:
Key: RECORD_TYPE
Values:
- Usage
- Tax
discount:
filter:
Dimensions:
Key: RECORD_TYPE
Values:
- Credit
- Refund
- Upfront
ec2:
filter:
Dimensions:
Key: SERVICE
Values:
- "EC2 - Other"
- "Amazon Elastic Compute Cloud - Compute"
```
You can exec command as below.
```bash
$ awscost --profile default
$ awscost --profile discount
$ awscost --profile ec2
```
#### group by tag
You can set up a group by tag.
Currently, this cannot be achieved using only the command line.
Write the following in yaml in $HOME/.awscost
The following is an example of grouping by the tag "Product"
```yaml:$HOME/.awscost
tag:
tags:
- Product
dimensions: []
```
You can exec command as below.
```bash
$ awscost --profile tag
```
## Various format(-t option)
example, use -t tsv.
default is simple.
```bash
$ awscost -d SERVICE -d OPERATION -t tsv
key 01-24 01-25 01-26 01-27 01-28 01-29 01-30 01-31 02-01 02-02
Total 2 2 2 2 2.02 2.01 2.01 2.01 2.5 1.67
EC2 - Other,NatGateway 1.08 1.08 1.08 1.08 1.08 1.08 1.08 1.08 1.08 0.9
Amazon Elastic Compute Cloud - Compute,RunInstances 0.55 0.55 0.55 0.55 0.55 0.55 0.55 0.55 0.55 0.46
...
```
### support format
- simple(default)
- plain
- github
- grid
- fancy_grid
- pipe
- orgtbl
- jira
- presto
- psql
- rst
- mediawiki
- moinmoin
- youtrack
- html
- latex
- latex_raw
- latex_booktabs
- textile
- tsv
## Settings
aws auth support following.
* environment variables
* profile(use --aws-profile option.)
* instance profile
## Python API
```py
from awscost.cost_explorer import CostExplorer
from dateutil.relativedelta import relativedelta
from datetime import datetime
start = (datetime.today() - relativedelta(months=3)).strftime("%Y-%m-01")
end = datetime.today().strftime("%Y-%m-01")
cost_explorer = CostExplorer(
granularity="MONTHLY",
start=start,
end=end,
dimensions=["SERVICE"],
metrics="UnblendedCost",
threshold=1.0,
).get_cost_and_usage_total_and_group_by()
# return dict data.
cost_explorer # =>
# { 'AWS CloudTrail': {'2019-11': 4.44, '2019-12': 6.17, '2020-01': 4.38},
# 'AWS Lambda': {'2019-11': 0.0, '2019-12': 0.0, '2020-01': 0.0},
# ...
# 'Total': {'2019-11': 67.15, '2019-12': 72.22, '2020-01': 68.11}}
```
### matplotlib
```py
...
import matplotlib.pyplot as plt
plt.figure(figsize=(25, 15), dpi=100)
plt.xlabel('month', fontsize=16)
plt.ylabel('$', fontsize=16)
plt.grid(True)
for i, (service_name, v) in enumerate(cost_explorer.items()):
left = list(v.keys())
height = list(v.values())
plt.plot(left, height, linewidth=2, label=service_name, marker='o')
plt.legend(loc='best', fontsize=15, numpoints=5)
plt.show()
```
## iam policy
```json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "xxxxxxxxx",
"Effect": "Allow",
"Action": [
"ce:GetCostAndUsage"
],
"Resource": "*"
}
]
}
```
## CI
### install test package
```bash
$ ./scripts/ci.sh install-test
```
### test
```bash
$ ./scripts/ci.sh run-test
```
flake8 and black and pytest.
### release pypi
```bash
$ ./scripts/ci.sh release
```
git tag and pypi release.
Raw data
{
"_id": null,
"home_page": null,
"name": "awscost",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "awscost, tool, aws",
"author": null,
"author_email": "Hiroshi Toyama <toyama0919@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/da/d9/f345b780a1e451530e521c3a2ce68deaef63425d059495cef045be5e5f18/awscost-0.3.2.tar.gz",
"platform": null,
"description": "# awscost\n\n[![PyPI version](https://badge.fury.io/py/awscost.svg)](https://badge.fury.io/py/awscost)\n[![Build Status](https://github.com/toyama0919/awscost/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/toyama0919/awscost/actions/workflows/ci.yml)\n\nCommand Line utility for Provides aws cost very easy to see.\n\nSupports python 3.7 or later.\n\n## Install\n\n```bash\n$ pip install awscost\n```\n\n## Examples\n\n### show cost\n\nshow cost latest 5 months.\n\n```bash\n$ awscost\nkey 2019-07 2019-08 2019-09 2019-10 2019-11 2019-12\n-------------------------------------- --------- --------- --------- --------- --------- ---------\nTotal 348.34 97.4 98.46 106.47 67.25 7.84\nEC2 - Other 34.28 34.28 33.2 34.28 33.63 3.01\nAmazon Elastic Compute Cloud - Compute 17.11 17.11 16.56 17.11 17.13 1.47\nAWS Cost Explorer 0.56 1.44\nTax 25.8 7.22 7.27 9.72 6.12 0.69\nAWS CloudTrail 3.29 3.21 4.15 5.57 4.44 0.61\nAWS Key Management Service 0 0 2.8 4 4 0.35\nAmazonCloudWatch 1.5 0.01 0 0 0.88 0.11\nAmazon Route 53 0.1 0.1 0.1 0.1 0.1 0.1\nAmazon Simple Storage Service 0.25 0.24 0.27 0.45 0.4 0.05\nAWS Lambda 0 0 0 0 0 0\nAmazon DynamoDB 0 0 0 0 0\nAmazon Elastic File System 0 0 0 0 0 0\nAmazon SageMaker 266 35.22 34.11 35.22 0\nAmazon Simple Notification Service 0 0 0\nAmazon Polly 0\nAmazon Simple Queue Service 0\n```\n\nshow cost latest 3 days, group by SERVICE and operation.\n\n```bash\n$ awscost -g DAILY -p 3 -d SERVICE -d OPERATION\nkey 2019-12-01 2019-12-02 2019-12-03\n------------------------------------------------------------ ------------ ------------ ------------\nTotal 2.87 2.1 2.87\nGetCostAndUsage,AWS Cost Explorer 0.02 1.42\nNatGateway,EC2 - Other 1.08 1.08 0.77\nRunInstances,Amazon Elastic Compute Cloud - Compute 0.55 0.55 0.37\nNone,AWS CloudTrail 0.22 0.22 0.17\nUnknown,AWS Key Management Service 0.13 0.13 0.09\nUnknown,AmazonCloudWatch 0.04 0.04 0.03\nCreateVolume-Gp2,EC2 - Other 0.03 0.03 0.01\nPutObject,Amazon Simple Storage Service 0.02 0.02 0.01\nNoOperation,Tax 0.25\n...\n```\n\n### support dimensions\n\n* AZ\n* INSTANCE_TYPE\n* LINKED_ACCOUNT\n* OPERATION\n* PURCHASE_TYPE\n* SERVICE\n* USAGE_TYPE\n* PLATFORM\n* TENANCY\n* RECORD_TYPE\n* LEGAL_ENTITY_NAME\n* DEPLOYMENT_OPTION\n* DATABASE_ENGINE\n* CACHE_ENGINE\n* INSTANCE_TYPE_FAMILY\n* REGION\n* BILLING_ENTITY\n* RESERVATION_ID\n* SAVINGS_PLANS_TYPE\n* SAVINGS_PLAN_ARN\n* OPERATING_SYSTEM\n\nsee. https://docs.aws.amazon.com/aws-cost-management/latest/APIReference/API_GetDimensionValues.html\n\n### support filter\n\n```bash\nawscost --filter '{\n \"Not\": {\n \"Dimensions\": {\n \"Key\": \"RECORD_TYPE\",\n \"Values\": [\"Credit\", \"Refund\", \"Upfront\"]\n }\n }\n}'\n```\n\n## config file($HOME/.awscost)\n\n```yaml:$HOME/.awscost\ndefault:\n metrics: AmortizedCost\n filter:\n Dimensions:\n Key: RECORD_TYPE\n Values:\n - Usage\n - Tax\n\ndiscount:\n filter:\n Dimensions:\n Key: RECORD_TYPE\n Values:\n - Credit\n - Refund\n - Upfront\n\nec2:\n filter:\n Dimensions:\n Key: SERVICE\n Values:\n - \"EC2 - Other\"\n - \"Amazon Elastic Compute Cloud - Compute\"\n```\n\nYou can exec command as below.\n\n```bash\n$ awscost --profile default\n$ awscost --profile discount\n$ awscost --profile ec2\n```\n\n#### group by tag\n\nYou can set up a group by tag.\n\nCurrently, this cannot be achieved using only the command line.\n\nWrite the following in yaml in $HOME/.awscost\n\nThe following is an example of grouping by the tag \"Product\"\n\n```yaml:$HOME/.awscost\ntag:\n tags:\n - Product\n dimensions: []\n```\n\nYou can exec command as below.\n\n```bash\n$ awscost --profile tag\n```\n\n## Various format(-t option)\n\nexample, use -t tsv.\n\ndefault is simple.\n\n```bash\n$ awscost -d SERVICE -d OPERATION -t tsv\nkey 01-24 01-25 01-26 01-27 01-28 01-29 01-30 01-31 02-01 02-02\nTotal 2 2 2 2 2.02 2.01 2.01 2.01 2.5 1.67\nEC2 - Other,NatGateway 1.08 1.08 1.08 1.08 1.08 1.08 1.08 1.08 1.08 0.9\nAmazon Elastic Compute Cloud - Compute,RunInstances 0.55 0.55 0.55 0.55 0.55 0.55 0.55 0.55 0.55 0.46\n...\n```\n\n### support format\n- simple(default)\n- plain\n- github\n- grid\n- fancy_grid\n- pipe\n- orgtbl\n- jira\n- presto\n- psql\n- rst\n- mediawiki\n- moinmoin\n- youtrack\n- html\n- latex\n- latex_raw\n- latex_booktabs\n- textile\n- tsv\n\n## Settings\n\naws auth support following.\n\n* environment variables\n* profile(use --aws-profile option.)\n* instance profile\n\n\n\n## Python API\n\n```py\nfrom awscost.cost_explorer import CostExplorer\nfrom dateutil.relativedelta import relativedelta\nfrom datetime import datetime\n\nstart = (datetime.today() - relativedelta(months=3)).strftime(\"%Y-%m-01\")\nend = datetime.today().strftime(\"%Y-%m-01\")\n\ncost_explorer = CostExplorer(\n granularity=\"MONTHLY\",\n start=start,\n end=end,\n dimensions=[\"SERVICE\"],\n metrics=\"UnblendedCost\",\n threshold=1.0,\n).get_cost_and_usage_total_and_group_by()\n\n# return dict data.\ncost_explorer # =>\n# { 'AWS CloudTrail': {'2019-11': 4.44, '2019-12': 6.17, '2020-01': 4.38},\n# 'AWS Lambda': {'2019-11': 0.0, '2019-12': 0.0, '2020-01': 0.0},\n# ...\n# 'Total': {'2019-11': 67.15, '2019-12': 72.22, '2020-01': 68.11}}\n\n```\n\n### matplotlib\n\n```py\n...\n\nimport matplotlib.pyplot as plt\n\nplt.figure(figsize=(25, 15), dpi=100)\nplt.xlabel('month', fontsize=16)\nplt.ylabel('$', fontsize=16)\nplt.grid(True)\nfor i, (service_name, v) in enumerate(cost_explorer.items()):\n left = list(v.keys())\n height = list(v.values())\n plt.plot(left, height, linewidth=2, label=service_name, marker='o')\nplt.legend(loc='best', fontsize=15, numpoints=5)\n\nplt.show()\n\n```\n\n## iam policy\n\n```json\n{\n \"Version\": \"2012-10-17\",\n \"Statement\": [\n {\n \"Sid\": \"xxxxxxxxx\",\n \"Effect\": \"Allow\",\n \"Action\": [\n \"ce:GetCostAndUsage\"\n ],\n \"Resource\": \"*\"\n }\n ]\n}\n```\n\n## CI\n\n### install test package\n\n```bash\n$ ./scripts/ci.sh install-test\n```\n\n### test\n\n```bash\n$ ./scripts/ci.sh run-test\n```\n\nflake8 and black and pytest.\n\n### release pypi\n\n```bash\n$ ./scripts/ci.sh release\n```\n\ngit tag and pypi release.\n",
"bugtrack_url": null,
"license": null,
"summary": "Command Line utility for cost of aws.",
"version": "0.3.2",
"project_urls": {
"Homepage": "https://github.com/toyama0919/awscost"
},
"split_keywords": [
"awscost",
" tool",
" aws"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "dad9f345b780a1e451530e521c3a2ce68deaef63425d059495cef045be5e5f18",
"md5": "20b9df9de0dbe99b2a06a23921ea36b7",
"sha256": "da6a4c4eb366d0c0b59e7d6db577f84fec528fc1f83d1ef38ac590e0eef0fd85"
},
"downloads": -1,
"filename": "awscost-0.3.2.tar.gz",
"has_sig": false,
"md5_digest": "20b9df9de0dbe99b2a06a23921ea36b7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 12019,
"upload_time": "2024-07-07T12:33:10",
"upload_time_iso_8601": "2024-07-07T12:33:10.957070Z",
"url": "https://files.pythonhosted.org/packages/da/d9/f345b780a1e451530e521c3a2ce68deaef63425d059495cef045be5e5f18/awscost-0.3.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-07 12:33:10",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "toyama0919",
"github_project": "awscost",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"tox": true,
"lcname": "awscost"
}