This is a simple and quick tutorial to explain how to do cost analysis on your AWS account from command line. There is a new open-source project on GitHub, aws-cost-cli that can fetch all the cost details right on your terminal. it analyzes your AWS account and the resources that you are using. It then generates a very simple comprehensive cost report in which you can see the outstanding cost report.
This command line tool can fetch the cost of current month, last 7 days, last month, and yesterday. You can see all these details right in the terminal by running a very simple command. If you have the official AWS Cli installed and configured already then you don’t have to do anything else extra. Just install it and start using it.
But in case you don’t have AWS Cli already set up on your PC, then you will have to manually specify your access key and then access secret in the aws-cost-cli tool in order to use it.
How to do cost analysis on your AWS account from Command Line?
You can simply start by installing this globally on your PC. This is a cross-platform tool, and you can install it through NodeJS. Just run this command in the terminal or the command prompt.
npm install -g aws-cost-cli
Now, after it has been installed, you can start using it right away. If AWS Cli is already configured on your PC, then it will use the AWS credentials from there. Otherwise, you can use the following command line arguments to configure AWS account is and secret access key.
aws-cost -k [key]-s [secret]-r [region]
Issue this command to get the cost analysis result. It generates the cost report like this. It takes some time in the first attempt. Also, you need to make sure that at least the keys you are using must have read only access to your entire account.
Another command that you can use is this one below. This command will generate a simple result with only the cost summary without service breakdown.
In this way, you can use this simple command line tool to do AWS cost analysis right from the command line. The process is very simple and straightforward. Other nice feature on this command line tool is Slack integration. If you have a Slack token, then you can send the alerts to a Slack channel. Also, you can automate this as well on a server if you want to.
If you are looking for a simple command line based AWS cost explorer and analyzer, then you are at the tight place. aws-cost-cli will show you cost of each service that is being billed in your account. The cost breakdown that it generates is very nice and can be understood easily. I also liked the fact that it shows you the bill amount of last month that can be useful for comparison.