Open In App

How to View Billing Details with AWS CLI: A Step-by-Step Guide

Last Updated : 17 Apr, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The AWS CLI can help you work with AWS from a command line. Users can control services and do tasks like launch EC2 instances or make S3 buckets. The CLI lets users configure resources for Lambda, EKS, RDS, and more AWS offerings. A big benefit is that users can include CLI commands in scripts, whether shell-based, Python, or other code. This automation handles repeated actions, manages cloud infrastructure, and streamlines operations. The AWS CLI gives users a flexible tool to administer AWS resources. Its scripting integration enables automation, infrastructure as code deployment, and simplified cloud operations management.

The AWS CLI has many commands, each with its own rules. These rules follow a consistent style, making CLI use easier across AWS services. Also, it shows output like JSON, text, and tables, letting you choose how to see it. One great thing about the AWS CLI is how it works with other tools and services. For instance, you can use it with tools like AWS CloudFormation or Terraform that set up infrastructure based on code. Or, you could add it to your CI/CD pipelines to automate tasks.

Step-By-Step Procedure For View-Billing Using AWS CLI

Step 1: Log in to the AWS Console. Go to the AWS Management Console and log in to your AWS account.

Step 2: Launch one EC2 instance. (Note: you can perform this practical on the local computer as well by installing aws cli.)

Step 3: Connect to your ec2 instance and first of all, install AWS CLI on the instance Follow these steps to install the AWS CLI.

Step 4: After installing cli, now configure your credentials to give access to aws cli for interacting with AWS services.

aws-configure

Step 5: Paste the following command in the AWS terminal.

aws ce get-cost-and-usage --time-period Start=YYYY-MM-DD,End=YYYY-MM-DD --granularity MONTHLY --metrics "BlendedCost" --group-by Type=DIMENSION,Key=SERVICE

Note: Replace the time period according to your billing spending.

Step 6: You will see the following output spanning your monthly costs from the start date to the end date.

Output Spanning Your Monthly Costs

EC2 Cost

EFS COst

View Billing Using AWS-CLI for S3 Service

Step 1: Create a file named filters.json, which will contain the command for billing specific to aws s3.

{
"Dimensions": {
"Key": "SERVICE",
"Values": [
"Amazon Simple Storage Service"
]
}
}

Filters

Step 2: Write a command to get the billing for s3 of your AWS account.

Note: Replace the time period as per the monthly spending you want to retrieve.

aws ce get-cost-and-usage \
--time-period Start=YY-MM-DD,End=YY-MM-DD \
--granularity MONTHLY \
--metrics "BlendedCost," "UnblendedCost," "UsageQuantity" \
--group-by Type=DIMENSION,Key=SERVICE Type=TAG,Key=Environment \
--filter file://filters.json

S3-CLI

Step 3: After entering the command, you will see the output like this, which contains your monthly cost spent on AWS and also the usage quantity.

s3-output

s3-output

Conclusion

In this article, we have gone through a simple introduction of what exactly AWS cli is and why many users prefer to use it. We have also understood the step-by-step procedure for viewing the AWS account bill using AWS cli, and if billing is needed for a specific AWS service, then for that, what is the step-by-step procedure?

View-Billing — AWS CLI – FAQs

What permissions are needed to view billing information with the AWS CLI?

To view billing information, your AWS IAM user or role needs permissions to access AWS Cost Explorer and the necessary billing data. You can assign the required permissions using IAM policies.

Is it possible to filter billing data to view costs for specific services or resources?

Yes, you can filter billing data to view costs for specific services or resources. Use the –filter option in the AWS CLI command and specify filter criteria based on service names, resource IDs, usage types, etc.

What is “blended cost” in AWS billing?

“Blended Cost” is a metric in AWS billing that represents the average cost per hour across all usage, combining both reserved and on-demand instance pricing. It provides an overall view of your AWS spending, considering both types of instance pricing.

Is it possible to customize the output format of billing data obtained via the AWS CLI?

Yes, you can customize the output format of billing data obtained via the AWS CLI. Use the –output option to specify the output format, such as json, text, or table.



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads