CLI tool to perform cost analysis on your AWS account
Install the package globally or alternatively you can also use npx
npm install -g aws-cost-cli
In order to use the CLI, you need to pass the AWS credentials. You can either pass them through the options i.e.:
aws-cost --access-key [key] --secret-key [secret] --region [region]
# or use the shorthand version
aws-cost -k [key] -s [secret] -r [region]
or if you have configured the credentials using aws-cli, you can simply run the following command:
aws-cost
To configure the credentials using aws-cli, have a look at the aws-cli docs for more information.
The default usage is to get the cost breakdown by service
aws-cost
You will get the following output
You can also get the summary of the cost without the service breakdown
aws-cost --summary
You will get the following output
You can also get the output as plain text
aws-cost --text
You will get the following output in response
You can also get the output as JSON
aws-cost --json
You will get the following output in response
{
"account": "theroadmap",
"totals": {
"lastMonth": 0.38,
"thisMonth": 11.86,
"last7Days": 1.29,
"yesterday": 0.22
},
"totalsByService": {
"lastMonth": {
"AmazonCloudWatch": 0,
"Tax": 0,
"AWS Key Management Service": 0,
"AWS Service Catalog": 0,
"Amazon Simple Email Service": 0.38,
"Amazon Simple Notification Service": 0,
"Amazon Simple Storage Service": 0.00001
},
"thisMonth": {
"AmazonCloudWatch": 0,
"Tax": 0,
"AWS Key Management Service": 0,
"AWS Service Catalog": 0,
"Amazon Simple Email Service": 11.85,
"Amazon Simple Notification Service": 0,
"Amazon Simple Storage Service": 0
},
"last7Days": {
"AmazonCloudWatch": 0,
"Tax": 0,
"AWS Key Management Service": 0,
"AWS Service Catalog": 0,
"Amazon Simple Email Service": 1.28,
"Amazon Simple Notification Service": 0,
"Amazon Simple Storage Service": 0
},
"yesterday": {
"AmazonCloudWatch": 0,
"Tax": 0,
"AWS Key Management Service": 0,
"AWS Service Catalog": 0,
"Amazon Simple Email Service": 0.22,
"Amazon Simple Notification Service": 0,
"Amazon Simple Storage Service": 0
}
}
}
For the simple usage, just run the command without any options. The output will be a table with the cost breakdown by service. Optionally, you can pass the following options to modify the output:
$ aws-cost --help
Usage: aws-cost [options]
A CLI tool to perform cost analysis on your AWS account
Options:
-V, --version output the version number
-k, --access-key [key] AWS access key
-s, --secret-key [key] AWS secret key
-r, --region [region] AWS region
-p, --profile [profile] AWS profile to use (default: "default")
-j, --json Get the output as JSON
-s, --summary Get only the summary without service breakdown
-t, --text Get the output as plain text (no colors / tables)
-v, --version Get the version of the CLI
-h, --help Get the help of the CLI
Regarding the credentials, you need to have the following permissions in order to use the CLI:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"iam:ListAccountAliases",
"ce:GetCostAndUsage"
],
"Resource": "*"
}
]
}
MIT © Kamran Ahmed