Save and mail a cost view
Save a cost explorer question under a name, with a range that moves along, share it or keep it private, and have it mailed every month with its CSV.
A saved view holds the range, the granularity, the grouping and the filters. Its range is relative (Last month, This month, Last 30 days, …), so the view keeps its meaning, or fixed dates. Replace Shop by service with a name of your own; names are unique in the organization.
Prerequisites
- Permission for
billing:CreateCostView. Without it, the console offers no Save this view. billing:GetCostAndUsageto open Cost explorer and to see saved views.billing:UpdateCostViewto change a view andbilling:DeleteCostViewto delete one.iam:UpdateOrganizationfor a view that groups or filters by where resources run.- Room in the Saved cost views quota (see Quotas).
Save a view
- Open Cost explorer and set up the view (see Explore costs).
- Choose Save this view.
- For Name, enter Shop by service.
- For Range, choose a range that moves along, or the dates on screen (fixed).
- (Optional) Clear Shared with the organization to keep the view to yourself.
- (Optional) Select Mail monthly with its CSV (on the 2nd, 08:00, for the month before) and enter the recipients.
- Choose Save.
The view is listed under Open a saved view…; opening it sets the explorer to its question.
dcloud billing cost-views create --name "Shop by service" \
--state '{"range":{"type":"relative","preset":"last-month"},"groupBy":{"dimension":"service"}}'POST /billing/api/cost-views
{
"name": "Shop by service",
"state": { "range": { "type": "relative", "preset": "last-month" }, "groupBy": { "dimension": "service" } },
"report": { "enabled": true, "recipients": ["jane.doe@example.com"] }
}resource "dcloud_cost_view" "shop_by_service" {
name = "Shop by service"
state = jsonencode({
range = { type = "relative", preset = "last-month" }
granularity = "day"
groupBy = { dimension = "service" }
filters = []
})
report = jsonencode({ enabled = true, recipients = ["jane.doe@example.com"] })
}Write all four keys of state: the API fills in the ones left out.
The presets are last-7-days, last-30-days, last-90-days, month-to-date, last-month,
last-3-months and year-to-date; a fixed range is { "type": "fixed", "start", "end" }.
Result
A shared view is visible to everyone with billing:GetCostAndUsage; a private one only to you, and
answers 404 for everyone else. A view with its monthly mail on is sent on the 2nd for the month
before, with the view's grouping and filters and a CSV of the month's cost lines, to the view's
recipients. GET /billing/api/cost-views/{id}/report shows that mail for a month without sending
it.
Change or delete a view
The console deletes the open view with Delete view, at once, without asking again; it does not change views. Over the CLI and the API:
dcloud billing cost-views update view-id --no-shared
dcloud billing cost-views delete view-idDeleting a view stops its monthly mail.
When saving is refused
409"A cost view named “…” already exists" when the name is taken.409"Quota exceeded: Saved cost views (billing.cost-views) — …" past the quota.403"Grouping or filtering by where resources run needs iam:UpdateOrganization (the org’s Infrastructure settings)".