Zum Inhalt springen

Download FOCUS reports from Object Storage

Diese Seite ist noch nicht in deiner Sprache verfügbar. Englische Seite aufrufen

Assuming you have already set up a STACKIT Object Storage bucket and a FOCUS export schedule, you can now download the reports. The Object Storage offering from STACKIT is S3-compatible, so there is a wide range of options to choose from. In this guide we want to highlight some common ones.

Use Python to access reports programmatically.

Prerequisites

  • Python 3 installed.
  • Code editor (e.g., Visual Studio Code).
  1. Create a directory for your project and navigate into it.

    Terminal window
    mkdir -p "desired/project/folder"
    cd "desired/project/folder"
  2. Initialize a virtual environment and install boto3.

    Terminal window
    python3 -m venv .venv
    source .venv/bin/activate
    pip install boto3
  3. Set your credentials as environment variables. If you don’t have credentials, see Create and delete Object Storage credentials

    Terminal window
    export ACCESS_KEY_ID="<CHANGE ME>"
    export SECRET_ACCESS_KEY="<CHANGE ME>"
  4. Create a script file named focus-downloader.py. This script downloads the FOCUS report from your bucket (your-bucket) and saves it to a local path (local/path/to/downloaded-report.csv).

    import boto3
    import os
    import sys
    access_key_id = os.getenv('ACCESS_KEY_ID')
    secret_access_key = os.getenv('SECRET_ACCESS_KEY')
    if not access_key_id:
    print('Environment variable ACCESS_KEY_ID empty!')
    sys.exit(1)
    if not secret_access_key:
    print('Environment variable SECRET_ACCESS_KEY empty!')
    sys.exit(1)
    s3 = boto3.client(
    's3',
    endpoint_url='https://object.storage.eu01.stackit.schwarz',
    aws_access_key_id=access_key_id,
    aws_secret_access_key=secret_access_key,
    )
    s3.download_file('your-bucket', 'path/to/report.csv', 'local/path/to/downloaded-report.csv')
  5. Run the script:

    python3 focus-downloader.py
  6. Verify the download. The file appears in the specified local path (e.g., local/path/to/downloaded-report.csv)