Skip to content

Export

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",
},
});