LinuxCommandLibrary

aws-ce

Manage AWS Cost Explorer resources

TLDR

Create anomaly monitor

$ aws ce create-anomaly-monitor --monitor [monitor_name] --monitor-type [monitor_type]
copy

Create anomaly subscription
$ aws ce create-anomaly-subscription --subscription [subscription_name] --monitor-arn [monitor_arn] --subscribers [subscribers]
copy

Get anomalies
$ aws ce get-anomalies --monitor-arn [monitor_arn] --start-time [start_time] --end-time [end_time]
copy

Get cost and usage
$ aws ce get-cost-and-usage --time-period [start_date]/[end_date] --granularity [granularity] --metrics [metrics]
copy

Get cost forecast
$ aws ce get-cost-forecast --time-period [start_date]/[end_date] --granularity [granularity] --metric [metric]
copy

Get reservation utilization
$ aws ce get-reservation-utilization --time-period [start_date]/[end_date] --granularity [granularity]
copy

List cost category definitions
$ aws ce list-cost-category-definitions
copy

Tag resource
$ aws ce tag-resource --resource-arn [resource_arn] --tags [tags]
copy

SYNOPSIS

aws ce <command> [global-options] [--cli-input-json file] [--generate-cli-skeleton [version]]

PARAMETERS

--cli-input-json
    Reads arguments from the JSON file specified. Useful for piping data.

--generate-cli-skeleton
    Prints a JSON skeleton for the command's --cli-input-json option.

--output
    Output format: json|text|table|yaml|yaml-stream.

--query
    JMESPath query to filter results.

--no-paginate
    Disable automatic pagination.

--paginate
    Enable automatic pagination (default).

--profile
    Use specific profile from credentials file.

--region
    AWS region (e.g., us-east-1). Cost Explorer is global.

--debug
    Enable debug logging.

--endpoint-url
    Custom endpoint URL for service.

--no-verify-ssl
    Disable SSL certificate verification.

DESCRIPTION

The aws ce command is part of the AWS Command Line Interface (CLI) for interacting with the AWS Cost Explorer service.

AWS Cost Explorer provides intuitive visualizations and reports to help you dive deep into your cost and usage data.
Through the CLI, you can programmatically retrieve cost and usage metrics, create cost forecasts, get recommendations for cost optimization, manage anomaly detection monitors and subscriptions, and view dimension values.

Key capabilities include querying historical cost data with granular filters (e.g., by service, linked account, or tags), generating usage forecasts, detecting unusual spending patterns via anomaly detection, and rightsizing recommendations for EC2 instances.

It supports JSON input/output, pagination for large datasets, and integration with other AWS services.
Requires AWS CLI v2 installed, appropriate IAM permissions (e.g., ce:GetCostAndUsage), and configured credentials.
Ideal for automation scripts, CI/CD pipelines, or serverless functions analyzing billing data.

CAVEATS

Global service; data latency up to 24 hours. Requires Cost Explorer enabled in account. High-volume queries may hit API throttling. IAM policies must grant specific CE actions. Not for real-time billing.

COMMON SUBCOMMANDS

get-cost-and-usage: Retrieve filtered cost data.
get-cost-forecast: Generate cost projections.
get-anomaly-monitor: Manage anomaly detection.
get-rightsizing-recommendation: EC2 optimization suggestions.

EXAMPLE USAGE

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

PERMISSIONS

Needs policies like CostExplorerReadOnlyAccess or custom with ce:Get*, ce:Describe* actions.

HISTORY

Introduced with AWS CLI v1 in 2017 alongside Cost Explorer launch. Enhanced in CLI v2 (2020+) with better performance, pagination, and YAML support. API versions evolve (e.g., v1.0 for core, forecast additions in 2019).

SEE ALSO

aws(1)

Copied to clipboard