Skip to content

AWS.BCMDataExports reference

Source: src/AWS/BCMDataExports/Export.ts

An AWS Billing and Cost Management data export (Data Exports / CUR 2.0) — delivers billing and cost management data selected by an SQL query to an S3 bucket on a refresh cadence.

Data Exports is a global service pinned to us-east-1; exports are free (standard S3 storage rates apply to the delivered objects).

The destination bucket must grant the Data Exports service principals write access via its bucket policy (see the example below).

import * as AWS from "alchemy/AWS";
const bucket = yield* AWS.S3.Bucket("BillingData", {
forceDestroy: true,
policy: [
{
Effect: "Allow",
Principal: {
Service: [
"billingreports.amazonaws.com",
"bcm-data-exports.amazonaws.com",
],
},
Action: ["s3:PutObject", "s3:GetBucketPolicy"],
Resource: [bucket.bucketArn, AWS.interpolate`${bucket.bucketArn}/*`],
},
],
});
const cur = yield* AWS.BCMDataExports.Export("Cur2", {
dataQuery: {
queryStatement:
"SELECT identity_line_item_id, line_item_unblended_cost FROM COST_AND_USAGE_REPORT",
tableConfigurations: {
COST_AND_USAGE_REPORT: { TIME_GRANULARITY: "HOURLY" },
},
},
s3Destination: {
s3Bucket: bucket.bucketName,
s3Prefix: "cur2",
s3Region: "us-west-2",
},
});

Source: src/AWS/BCMDataExports/GetExecution.ts

Runtime binding for bcm-data-exports:GetExecution.

Bind this operation to an Export to read the status of one export execution (delivery run) — its status code, reason, and timestamps — from inside a function runtime. Useful for delivery monitors that alert when a refresh fails. Provide the implementation with Effect.provide(AWS.BCMDataExports.GetExecutionHttp).

// init — bind the operation to the export
const getExecution = yield* AWS.BCMDataExports.GetExecution(cur);
// runtime
const result = yield* getExecution({ ExecutionId: executionId });
const status = result.ExecutionStatus?.StatusCode;

Source: src/AWS/BCMDataExports/GetExport.ts

Runtime binding for bcm-data-exports:GetExport.

Bind this operation to an Export to read the export’s live definition — SQL query, table configurations, S3 destination, and refresh cadence — from inside a function runtime. Useful for cost dashboards that surface where their billing data lands. Provide the implementation with Effect.provide(AWS.BCMDataExports.GetExportHttp).

// init — bind the operation to the export
const getExport = yield* AWS.BCMDataExports.GetExport(cur);
// runtime
const { Export: definition } = yield* getExport();
const bucket = definition?.DestinationConfigurations.S3Destination.S3Bucket;

Source: src/AWS/BCMDataExports/GetTable.ts

Runtime binding for bcm-data-exports:GetTable.

An account-level operation (the table dictionary is not tied to any export) that reads the schema of a Data Exports table — its columns, data types, and descriptions for the given table properties. Useful for query builders that validate an SQL statement’s columns before calling UpdateExport. Provide the implementation with Effect.provide(AWS.BCMDataExports.GetTableHttp).

// init — account-level binding takes no resource
const getTable = yield* AWS.BCMDataExports.GetTable();
// runtime
const table = yield* getTable({ TableName: "COST_AND_USAGE_REPORT" });
const columns = (table.Schema ?? []).map((column) => column.Name);

Source: src/AWS/BCMDataExports/ListExecutions.ts

Runtime binding for bcm-data-exports:ListExecutions.

Bind this operation to an Export to page through the export’s historical executions (delivery runs) from inside a function runtime. Useful for delivery dashboards and monitors that scan for failed refreshes. Provide the implementation with Effect.provide(AWS.BCMDataExports.ListExecutionsHttp).

// init — bind the operation to the export
const listExecutions = yield* AWS.BCMDataExports.ListExecutions(cur);
// runtime
const result = yield* listExecutions({ MaxResults: 25 });
const failed = (result.Executions ?? []).filter(
(execution) =>
execution.ExecutionStatus.StatusCode === "DELIVERY_FAILURE",
);

Source: src/AWS/BCMDataExports/ListExports.ts

Runtime binding for bcm-data-exports:ListExports.

An account-level operation (no export argument) that enumerates every data export definition in the account. Useful for governance sweeps that audit where billing data is being delivered. Provide the implementation with Effect.provide(AWS.BCMDataExports.ListExportsHttp).

// init — account-level binding takes no resource
const listExports = yield* AWS.BCMDataExports.ListExports();
// runtime
const result = yield* listExports({ MaxResults: 100 });
const names = (result.Exports ?? []).map((e) => e.ExportName);

Source: src/AWS/BCMDataExports/ListTables.ts

Runtime binding for bcm-data-exports:ListTables.

An account-level operation (the table dictionary is not tied to any export) that enumerates every table available to Data Exports queries, with each table’s configurable properties. Useful for query builders that present the available data sources. Provide the implementation with Effect.provide(AWS.BCMDataExports.ListTablesHttp).

// init — account-level binding takes no resource
const listTables = yield* AWS.BCMDataExports.ListTables();
// runtime
const result = yield* listTables();
const names = (result.Tables ?? []).map((table) => table.TableName);