Repository navigation
Create OneLake Shortcuts in Gold
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.
Before running this notebook, ensure the following are in place:
-
Business Domain workspaces deployed — run
NB_SETUP_BUSINESS_DOMAINS.ipynbfirst. -
VAR_GOLD_SHORTCUTS_FMDVariable Library configured — all six variables must be populated (see Configuration below).
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.ipynbcan populate these values automatically when you provide them in its configuration cell.
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.
The notebook loads connection settings from the variable library:
ShortcutSettings = notebookutils.variableLibrary.getLibrary("VAR_GOLD_SHORTCUTS_FMD")For each table in ShortcutNames, the notebook:
- Constructs a OneLake target pointing to
Tables/<Shortcut_TargetSchema>/<TableName>in the Silver lakehouse. - Calls the Fabric REST API endpoint
POST /v1/workspaces/{workspaceId}/items/{lakehouseId}/shortcutswithshortcutConflictPolicy=CreateOrOverwrite. - 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.
- Open the notebook in the Business Domain Code workspace.
- Attach a default lakehouse if prompted (the notebook does not require one, but Spark session needs to start).
- Update
ShortcutNamesif needed. - Verify
VAR_GOLD_SHORTCUTS_FMDis configured correctly. - Run All cells.
Each shortcut creation prints a success message with the shortcut location, or an error code and message if it fails.
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")| Parameter | Resolved path |
|---|---|
| Shortcut created at |
Tables/<SourceSchema>/<TableName> in the Gold lakehouse |
| Shortcut points to |
Tables/<Shortcut_TargetSchema>/<TableName> in the Silver lakehouse |