AWS Billing GetCostAndUsage

AWS Billing GetCostAndUsage

Certified

Get AWS cost and usage from Cost Explorer

Calls the Cost Explorer GetCostAndUsage API for a time period and returns one row per time period and group. Cost Explorer is a paid API: AWS charges $0.01 for each paginated request, so request only the metrics, granularity and groups you need, and keep maxPages low. HOURLY granularity must be enabled on the account and is charged separately.

yaml
type: io.kestra.plugin.aws.billing.GetCostAndUsage

Get last month's unblended cost per AWS service and log the total.

yaml
id: aws_monthly_cost_by_service
namespace: company.finops

tasks:
  - id: cost
    type: io.kestra.plugin.aws.billing.GetCostAndUsage
    region: us-east-1
    accessKeyId: "{{ secret('AWS_ACCESS_KEY_ID') }}"
    secretKeyId: "{{ secret('AWS_SECRET_ACCESS_KEY') }}"
    startDate: "{{ now() | dateAdd(-1, 'MONTHS') | date('yyyy-MM-01') }}"
    endDate: "{{ now() | date('yyyy-MM-01') }}"
    granularity: MONTHLY
    metrics:
      - UnblendedCost
    groupBy:
      - SERVICE
    fetchType: FETCH

  - id: log_total
    type: io.kestra.plugin.core.log.Log
    message: "Last month: {{ outputs.cost.costTotals.UnblendedCost }} {{ outputs.cost.unit }} over {{ outputs.cost.size }} services"

Store daily cost of the last 7 days for one team tag, grouped by usage type.

yaml
id: aws_daily_cost_team
namespace: company.finops

tasks:
  - id: cost
    type: io.kestra.plugin.aws.billing.GetCostAndUsage
    region: us-east-1
    accessKeyId: "{{ secret('AWS_ACCESS_KEY_ID') }}"
    secretKeyId: "{{ secret('AWS_SECRET_ACCESS_KEY') }}"
    startDate: "{{ now() | dateAdd(-7, 'DAYS') | date('yyyy-MM-dd') }}"
    endDate: "{{ now() | date('yyyy-MM-dd') }}"
    granularity: DAILY
    metrics:
      - UnblendedCost
      - UsageQuantity
    groupBy:
      - USAGE_TYPE
    dimensionFilter:
      "TAG:team":
        - data-platform
Properties

End date

End of the time period, as yyyy-MM-dd. Exclusive for GetCostAndUsage and GetCostForecast, like in the Cost Explorer API (the whole month of January is 2026-01-01 to 2026-02-01); inclusive for GetAnomalies (2026-01-01 to 2026-01-31).

Possible Values
DAILYMONTHLYHOURLYUNKNOWN_TO_SDK_VERSION

Granularity

DAILY, MONTHLY or HOURLY. HOURLY must be enabled on the account.

SubTypestring

Metrics

Cost Explorer metrics to return, for example UnblendedCost, AmortizedCost, NetUnblendedCost, BlendedCost or UsageQuantity. At least one is required.

Start date

Start of the time period, inclusive, as yyyy-MM-dd.

Access Key Id in order to connect to AWS

If no credentials are defined, we will use the default credentials provider chain to fetch credentials.

Assets this task consumes as inputs or produces as outputs, for lineage tracking and the asset graph (Enterprise Edition). A flow declaring this property on a task is rejected in the open-source edition.

Definitions
assetFailureBehaviorstring
Possible Values
IGNOREFAILWARN

Asset failure behavior

Behavior applied to the task state when a declared asset fails to render, emit, or be persisted (e.g. a lock conflict): FAIL escalates it to FAILED, WARN (default) warns it if it would otherwise succeed, IGNORE leaves the state untouched.

enableAutobooleanstring

Whether to auto-register assets referenced dynamically at runtime that are not statically declared in inputs or outputs.

inputsarray

The assets consumed as inputs.

id*string
Min length1
typestring
outputs

The assets produced as outputs.

id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*string
Min length1

Custom asset type

descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150

Filter

Only include costs matching all entries. Keys use the same syntax as groupBy (SERVICE, TAG: team, COST_CATEGORY: env), values are the accepted values for that key.

The endpoint with which the SDK should communicate

This property allows you to use a different S3 compatible storage backend.

DefaultSTORE
Possible Values
STOREFETCHFETCH_ONENONE

Fetch strategy

Default STORE writes all rows to internal storage. FETCH returns all rows, FETCH_ONE the first row, NONE only the totals. FETCH_ONE stops requesting pages as soon as a page returns a row; if more pages exist, truncated is true and costTotals only cover the pages read.

SubTypestring

Group by

Up to 2 groupings. A plain value is a dimension (e.g. SERVICE, LINKED_ACCOUNT, USAGE_TYPE, REGION), TAG: <key> groups by a cost allocation tag and COST_CATEGORY: <name> by a cost category.

Default10

Maximum number of pages

Stops after this many GetCostAndUsage requests, each one costing $0.01, and logs a warning if more data was available. Default 10, between 1 and 1000.

AWS region with which the SDK should communicate

Secret Key Id in order to connect to AWS

If no credentials are defined, we will use the default credentials provider chain to fetch credentials.

AWS session token, retrieved from an AWS token service, used for authenticating that this user has received temporary permissions to access a given resource

If no credentials are defined, we will use the default credentials provider chain to fetch credentials.

The AWS STS endpoint with which the SDKClient should communicate

AWS STS Role

The Amazon Resource Name (ARN) of the role to assume. If set the task will use the StsAssumeRoleCredentialsProvider. If no credentials are defined, we will use the default credentials provider chain to fetch credentials.

AWS STS External Id

A unique identifier that might be required when you assume a role in another account. This property is only used when an stsRoleArn is defined.

DefaultPT15M

AWS STS Session duration

The duration of the role session (default: 15 minutes, i.e., PT15M). This property is only used when an stsRoleArn is defined.

AWS STS Session name

This property is only used when an stsRoleArn is defined.

SubTypenumber

Cost totals

Sum of each requested cost metric over the rows read, keyed by metric name (e.g. costTotals.UnblendedCost). Usage metrics (UsageQuantity, NormalizedUsageAmount) are not totaled because their units differ between rows.

First row

Single row when fetchType is FETCH_ONE.

SubTypeobject

Rows

All rows when fetchType is FETCH. Each row has start, end, estimated, keys (the group values), and for each metric its amount (e.g. UnblendedCost) and unit (e.g. UnblendedCostUnit).

Row count

Number of rows in the output: all rows read for FETCH, STORE and NONE, 1 or 0 for FETCH_ONE.

Truncated

True when more pages were available but not read: maxPages was reached, or fetchType is FETCH_ONE and the first page with a row was not the last one. costTotals then only cover the pages read.

Cost unit

Currency of the cost metrics in costTotals, usually USD. Usage metric units are not considered.

Formaturi

Stored data URI

Internal storage URI of an ION file with all rows when fetchType is STORE.

Unitrows

Number of rows fetched or stored.

Unitrequests

Number of paid Cost Explorer requests made.