Downloading a Cost Report
Download a cost report in Billing and Cost Management.
A cost report is a file stored as an object in a bucket. For general information about downloading an object, see Downloading an Object Storage Object.
For information about listing cost reports, see Listing Cost Reports.
- On the Cost and Usage Reports list page, find the cost report that you want to download. If you need help finding the list page or the cost report, see Listing Cost Reports.
- From the for the cost report, select Download report.
- Note
Cost reports are stored in the tenancy's home region. The Object Storage namespace used for the reports isbling
. The bucket name is the tenancy OCID.Use the oci os object get command and required parameters to download cost reports in the tenancy:
oci os object get --bucket-name bucket-name --name object-name --file file-name
Example (reference the Python SDK code example shown in the API task):
oci os object get --namespace-name bling --bucket-name {customer_tenancy_ocid} --name reports/usage-csv/{report_name}.csv.gz --file {local_report_name}.csv.gz
For a complete list of parameters and values for CLI commands, see the CLI Command Reference.
- Note
Cost reports are stored in the tenancy's home region. The Object Storage namespace used for the reports isbling
. The bucket name is the tenancy OCID.Run the GetObject operation to download a cost report.
The following example shows how to download a cost report using a Python script:
Note
This example has a specific tenancy OCID, because the reports are stored in an Oracle-owned Object Storage bucket hosted by Oracle Cloud Infrastructure, and not a customer's tenancy.import oci import os # This script downloads all of the cost, usage, (or both) reports for a tenancy (specified in the config file). # # Pre-requisites: Create an IAM policy to endorse users in your tenancy to read cost reports from the OCI tenancy. # # Example policy: # define tenancy reporting as ocid1.tenancy.oc1..aaaaaaaaned4fkpkisbwjlr56u7cj63lf3wffbilvqknstgtvzub7vhqkggq # endorse group <group_name> to read objects in tenancy reporting # # Note - The only value you need to change is the <group_name> with your own value. Do not change the OCID in the first statement. reporting_namespace = 'bling' # Download all usage and cost files. You can comment out based on the specific need: prefix_file = "" # For cost and usage files # prefix_file = "reports/cost-csv" # For cost # prefix_file_focus = "FOCUS Reports" # For FOCUS reports # Update these values destintation_path = 'downloaded_reports' # Make a directory to receive reports if not os.path.exists(destintation_path): os.mkdir(destintation_path) # Get the list of reports config = oci.config.from_file(oci.config.DEFAULT_LOCATION, oci.config.DEFAULT_PROFILE) reporting_bucket = config['tenancy'] object_storage = oci.object_storage.ObjectStorageClient(config) report_bucket_objects = oci.pagination.list_call_get_all_results(object_storage.list_objects, reporting_namespace, reporting_bucket, prefix=prefix_file) for o in report_bucket_objects.data.objects: print('Found file ' + o.name) object_details = object_storage.get_object(reporting_namespace, reporting_bucket, o.name) filename = o.name.rsplit('/', 1)[-1] with open(destintation_path + '/' + filename, 'wb') as f: for chunk in object_details.data.raw.stream(1024 * 1024, decode_content=False): f.write(chunk) print('----> File ' + o.name + ' Downloaded')