Search code examples
amazon-web-servicesaws-lambdaboto3billing

Is there any way to Download billing reports in an automated way?


Is there any way to automate all of the "download CSV" options in AWS defaults reports and push it to S3 storage using python lambda or by using any other services.?

Example,

The billing information can be downloaded from the 'bills' section of the AWS console. Screenshot attached

download csv billing report

billing report download csv popup


Solution

  • What you're looking for is the DBR (Detailed billing report - deprecated) or the CUR (Cost and allocation report) which is what you want to use.

    https://docs.aws.amazon.com/cur/latest/userguide/cur-create.html

    To create Cost and Usage Reports:

    • Sign in to the Billing and Cost Management console at https://console.aws.amazon.com/billing/home#/

    • On the navigation pane, choose Cost & Usage Reports.

    • Choose Create report.

    • For Report name, enter a name for your report.

    • For Additional report details, select Include resource IDs to include the IDs of each individual resource in the report.

    Note Including resource IDs will create individual line items for each of your resources. This can increase the size of your Cost and Usage Reports files significantly, based on your AWS usage.

    • For Data refresh settings, select whether you want the AWS Cost and Usage Reports to refresh if AWS applies refunds, credits, or support fees to your account after finalizing your bill. When a report refreshes, a new report is uploaded to Amazon S3.

    • Choose Next.

    • For S3 bucket, choose Configure.

    • In the Configure S3 Bucket dialog box, do one of the following:

      • Select an existing bucket from the drop down list and choose Next.
      • Enter a bucket name and the Region where you want to create a new bucket and choose Next.
    • Review the bucket policy, and select I have confirmed that this policy is correct and choose Save.

    • For Report path prefix, enter the report path prefix that you want prepended to the name of your report.

    • For Time granularity, choose one of the following:

      • Hourly if you want the line items in the report to be aggregated by the hour.
      • Daily if you want the line items in the report to be aggregated by the day.
      • Monthly if you want the line items in the report to be aggregated by month.
    • For Report versioning, choose whether you want each version of the report to overwrite the previous version of the report or to be delivered in addition to the previous versions.

    • Overwriting reports can save on Amazon S3 storage costs. Delivering new report versions can improve auditability of billing data over time.

    • For Enable report data integration for, select whether you want to enable your Cost and Usage Reports to integrate with Amazon Athena, Amazon Redshift, or Amazon QuickSight. The report is compressed in the following formats:

      • Athena: parquet format

      • Amazon Redshift or Amazon QuickSight: .gz compression

    • Choose Next.

    • After you have reviewed the settings for your report, choose Review and Complete.