Skip to content

Create OneLake Shortcuts in Gold

Erwin de Kreuk edited this page Apr 28, 2026 · 1 revision

NB_CREATE_SHORTCUTS — Create OneLake Shortcuts in Gold

Overview

NB_CREATE_SHORTCUTS is a PySpark notebook that automates the creation of OneLake shortcuts from a Silver layer lakehouse into a Gold layer lakehouse. It uses the Fabric REST API to register each shortcut, enabling Gold-layer reports and models to reference Silver tables without duplicating data.

Prerequisites

Before running this notebook, ensure the following are in place:

  1. Business Domain workspaces deployed — run NB_SETUP_BUSINESS_DOMAINS.ipynb first.
  2. VAR_GOLD_SHORTCUTS_FMD Variable Library configured — all six variables must be populated (see Configuration below).

Configuration

All connection settings are read at runtime from the VAR_GOLD_SHORTCUTS_FMD Variable Library. Open this library in your Business Domain Code workspace and populate the following variables:

Variable Description
SourceWorkspaceId GUID of the Gold workspace where shortcuts will be created
SourceLakehouseId GUID of the Gold lakehouse (shortcut destination)
SourceSchema Schema name inside the Gold lakehouse (e.g. gold)
Shortcut_TargetWorkspaceId GUID of the Silver workspace (shortcut source)
Shortcut_TargetLakehouseId GUID of the Silver lakehouse (shortcut source)
Shortcut_TargetSchema Schema name inside the Silver lakehouse (e.g. silver)

Tip: The setup notebook NB_SETUP_BUSINESS_DOMAINS.ipynb can populate these values automatically when you provide them in its configuration cell.

How It Works

Step 1 — Define shortcut names

At the top of the notebook, update the ShortcutNames list with the exact table names you want to create shortcuts for. These names are used as both the source path in the Silver lakehouse and the shortcut name in the Gold lakehouse.

ShortcutNames = [
    'Sales_BuyingGroups',
    'Sales_CustomerCategories',
    'Sales_InvoiceLines',
    'Sales_Invoices',
    'Sales_Orders',
    'Sales_OrderLines',
    'Sales_vCustomers',
    'Warehouse_PackageTypes',
    'Warehouse_StockItems'
]

Replace this list with the tables relevant to your business domain.

Step 2 — Load settings

The notebook loads connection settings from the variable library:

ShortcutSettings = notebookutils.variableLibrary.getLibrary("VAR_GOLD_SHORTCUTS_FMD")

Step 3 — Create shortcuts via Fabric REST API

For each table in ShortcutNames, the notebook:

  1. Constructs a OneLake target pointing to Tables/<Shortcut_TargetSchema>/<TableName> in the Silver lakehouse.
  2. Calls the Fabric REST API endpoint POST /v1/workspaces/{workspaceId}/items/{lakehouseId}/shortcuts with shortcutConflictPolicy=CreateOrOverwrite.
  3. Prints confirmation or failure details for each shortcut.

Authentication is handled automatically using a Fabric bearer token via notebookutils.credentials.getToken("pbi") — no passwords are stored.

Running the Notebook

  1. Open the notebook in the Business Domain Code workspace.
  2. Attach a default lakehouse if prompted (the notebook does not require one, but Spark session needs to start).
  3. Update ShortcutNames if needed.
  4. Verify VAR_GOLD_SHORTCUTS_FMD is configured correctly.
  5. Run All cells.

Each shortcut creation prints a success message with the shortcut location, or an error code and message if it fails.

Conflict Policy

The notebook uses CreateOrOverwrite as the conflict policy. This means:

  • If a shortcut with the same name already exists at the target path, it is overwritten.
  • Running the notebook multiple times is safe and idempotent.

To change this behaviour (e.g. to Abort to prevent accidental overwrites), modify the conflict_policy argument in the loop:

create_shortcut(..., conflict_policy="Abort")

Shortcut Path Convention

Parameter Resolved path
Shortcut created at Tables/<SourceSchema>/<TableName> in the Gold lakehouse
Shortcut points to Tables/<Shortcut_TargetSchema>/<TableName> in the Silver lakehouse

Clone this wiki locally