Accessing Cost and Usage Reports
Cost and usage reports are comma-separated value (CSV) files that are generated daily and stored in an Object Storage bucket. This topic describes how to access these reports.
Required IAM Policy
To use Oracle Cloud Infrastructure, you must be given the required type of access in a policy written by an administrator, whether you're using the Console or the REST API with an SDK, CLI, or other tool. If you try to perform an action and get a message that you don’t have permission or are unauthorized, confirm with your administrator the type of access you've been granted and which compartment you should work in.
Reports are generated in another tenancy and stored in an Oracle-owned Object Storage bucket. You must set up a cross-tenancy IAM policy to access your usage reports as shown below, changing the group name as appropriate:
define tenancy usage-report as ocid1.tenancy.oc1..aaaaaaaaned4fkpkisbwjlr56u7cj63lf3wffbilvqknstgtvzub7vhqkggq endorse group MyGroupName to read objects in tenancy usage-report
Using the Console
Open the navigation menu. Under Governance and Administration, go to Account Management and select Cost and Usage Reports.
- Click the report you want to download from the list, and follow your browser's instructions for downloading.
Using the API
For information about using the API and signing requests, see REST APIs and Security Credentials. For information about SDKs, see Software Development Kits and Command Line Interface.
To download a cost or usage report, use the Object Storage APIs. The reports are stored in the tenancy's home region. The Object Storage namespace used for the reports is
bling; the bucket name is the tenancy OCID.
The following example shows how to download a cost report, usage report (or both) using a Python script:
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. 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 = "reports/usage-csv" # For usage # 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 = 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')