Share Live Data Outside Snowflake Using Iceberg REST Catalog
Overview
Acme Analytics is a SaaS product-analytics company. One of its enterprise customers, Northwind Retail, wants its own product-usage data (sessions, feature usage, time in app) inside its Spark lakehouse. Northwind doesn't use Snowflake. Today, Acme ships a nightly CSV extract to an SFTP server. The data is a day old by the time it lands, the export job breaks whenever the schema changes, and nobody can say for sure who has a copy.
Open Data Sharing powered by Apache Polaris™ removes that pipeline. Acme shares a live, read-only Apache Iceberg™ table straight from Snowflake, and Northwind queries it from Apache Spark™ using the standard Iceberg REST Catalog API. There are no extracts and no copies, and Acme controls access with a token it can revoke at any time.
In this guide, you'll play both roles. First you'll be Acme's data engineer and set up the share in Snowflake. Then you'll switch to Northwind's data engineer and query the data from PySpark on your laptop.
Note: This guide authenticates the consumer with a programmatic access token (PAT). External consumers can also authenticate with workload identity federation (WIF). Either way, access is authorized with a bearer token on every request.
Prerequisites
- A Snowflake account (or free trial)
- Python 3.10 or later and Java 11 or 17 installed locally
- PySpark 3.5 (
pip install pyspark==3.5.*)
What You'll Learn
- How Open Data Sharing delivers Snowflake data to engines outside Snowflake without copying it
- How to create an external consumer and a programmatic access token
- How to share an Iceberg table through an external listing and get its catalog URL
- How to query shared data from Apache Spark over the Iceberg REST Catalog API
- How to revoke a consumer's access
What You'll Need
- A Snowflake account with the ACCOUNTADMIN role, or an admin who can run the role and grants block in the next step
- If your account uses a network policy, an admin must add an entry for the external consumer you create in this guide. Network policies are enforced for in-region shares only. They are not enforceable for cross-region shares.
What You'll Build
- A Snowflake-managed Iceberg table of customer usage events, shared through an external listing
- A local PySpark session that reads that table live, then loses access when the provider revokes the token
Setup: Role & Grants
Before we begin, we'll create a dedicated role for this Quickstart and grant it the privileges you'll need. If you don't have ACCOUNTADMIN access in your Snowflake account, send the SQL block below to your Snowflake admin. They can review and run it to provision the role on your behalf.
Open a new SQL worksheet in Snowsight (Projects > Workspaces) and run the following:
-- Run as ACCOUNTADMIN USE ROLE ACCOUNTADMIN; -- 1. Create the role for this Quickstart CREATE ROLE IF NOT EXISTS OPEN_SHARING_QS_ROLE; -- 2. Grant the role to the user who will run the Quickstart GRANT ROLE OPEN_SHARING_QS_ROLE TO USER <your_username>; -- 3. Warehouse privileges GRANT CREATE WAREHOUSE ON ACCOUNT TO ROLE OPEN_SHARING_QS_ROLE; -- 4. Database & schema privileges GRANT CREATE DATABASE ON ACCOUNT TO ROLE OPEN_SHARING_QS_ROLE; -- 5. Guide-specific grants GRANT CREATE EXTERNAL CONSUMER ON ACCOUNT TO ROLE OPEN_SHARING_QS_ROLE; GRANT CREATE SHARE ON ACCOUNT TO ROLE OPEN_SHARING_QS_ROLE; GRANT CREATE LISTING ON ACCOUNT TO ROLE OPEN_SHARING_QS_ROLE; -- 6. Switch into the role for the rest of the Quickstart USE ROLE OPEN_SHARING_QS_ROLE;
Note: If you don't have ACCOUNTADMIN access, send the SQL block above to your Snowflake admin to run on your behalf. Once the role is granted, run
USE ROLE OPEN_SHARING_QS_ROLE;and continue with the Quickstart.
Here's what the code does:
- Creates
OPEN_SHARING_QS_ROLEand grants it to you - Lets the role create its own warehouse and database, so it owns everything it builds
- Grants the three account-level privileges Open Data Sharing needs: creating external consumers, shares, and listings
Create the Iceberg Table
We're Acme's data engineer now. Let's create a warehouse, a database, and a Snowflake-managed Iceberg table that holds Northwind's product-usage events. Only Iceberg tables (and dynamic Iceberg tables) can be shared with non-Snowflake consumers, because the consumer reads the Iceberg metadata and data files directly. Snowflake-managed storage means you don't need to set up an external volume or a cloud bucket.
CREATE WAREHOUSE IF NOT EXISTS OPEN_SHARING_QS_WH WAREHOUSE_SIZE = XSMALL AUTO_SUSPEND = 60; USE WAREHOUSE OPEN_SHARING_QS_WH; CREATE DATABASE IF NOT EXISTS ACME_PROVIDER_DB; CREATE SCHEMA IF NOT EXISTS ACME_PROVIDER_DB.CUSTOMER_SHARES; USE SCHEMA ACME_PROVIDER_DB.CUSTOMER_SHARES; CREATE OR REPLACE ICEBERG TABLE NORTHWIND_USAGE_EVENTS ( event_id INT, event_ts TIMESTAMP_NTZ(6), user_id STRING, feature STRING, session_seconds INT ) EXTERNAL_VOLUME = 'SNOWFLAKE_MANAGED' CATALOG = 'SNOWFLAKE';
Now let's fill the table with 30 days of synthetic usage events:
INSERT INTO NORTHWIND_USAGE_EVENTS SELECT SEQ4() AS event_id, DATEADD(second, -UNIFORM(0, 30 * 86400, RANDOM()), CURRENT_TIMESTAMP())::TIMESTAMP_NTZ(6) AS event_ts, 'user_' || UNIFORM(1, 250, RANDOM()) AS user_id, DECODE(UNIFORM(1, 5, RANDOM()), 1, 'dashboards', 2, 'reports', 3, 'alerts', 4, 'exports', 'funnels') AS feature, UNIFORM(10, 1800, RANDOM()) AS session_seconds FROM TABLE(GENERATOR(ROWCOUNT => 10000)); SELECT feature, COUNT(*) AS events, ROUND(AVG(session_seconds)) AS avg_seconds FROM NORTHWIND_USAGE_EVENTS GROUP BY feature ORDER BY events DESC;
You should see five features, each with roughly 2,000 events.
Here's what the code does:
- Creates an extra-small warehouse that suspends after a minute of inactivity
- Creates an Iceberg table stored in Snowflake-managed storage, with Snowflake as the catalog
- Generates 10,000 random events across 250 users and five product features
Create an External Consumer
Northwind doesn't have a Snowflake account, so Acme needs a way to identify them. An external consumer is a restricted identity that represents a party outside Snowflake. It's bound to your account's region, it can't log in to Snowsight, and you can't grant it roles. Its only job is to read data shared with it.
Let's create one for Northwind:
CREATE EXTERNAL CONSUMER IF NOT EXISTS NORTHWIND_RETAIL COMMENT = 'Northwind Retail data team' EMAIL = 'data@northwind.example.com'; SHOW EXTERNAL CONSUMERS LIKE 'NORTHWIND_RETAIL';
Next, Northwind needs a credential. In this guide, we'll use a programmatic access token (PAT). Tokens expire after 15 days by default. We'll set a shorter 7-day expiry, which is a sensible habit for tokens that leave your organization:
ALTER EXTERNAL CONSUMER NORTHWIND_RETAIL ADD PAT northwind_pat DAYS_TO_EXPIRY = 7 COMMENT = 'Spark access for Northwind data team';
Important: Copy the
token_secretvalue from the result now and keep it somewhere safe. Snowflake shows the secret only once. If you lose it, you'll need to add a new token.
You can check the token and its expiry date at any time:
SHOW USER PROGRAMMATIC ACCESS TOKENS FOR EXTERNAL CONSUMER NORTHWIND_RETAIL;
Look at the expires_at column. It should be seven days from now.
Create an External Listing
Now let's package the table for Northwind. Sharing to a non-Snowflake consumer uses the same building blocks as any Snowflake share: a share that holds grants, and a listing that defines who can access it. The difference is the listing's manifest, which includes an open_sharing section and names the external consumer as the target.
First, create the share and grant it access to the table:
CREATE SHARE IF NOT EXISTS NORTHWIND_USAGE_SHARE; GRANT USAGE ON DATABASE ACME_PROVIDER_DB TO SHARE NORTHWIND_USAGE_SHARE; GRANT USAGE ON SCHEMA ACME_PROVIDER_DB.CUSTOMER_SHARES TO SHARE NORTHWIND_USAGE_SHARE; GRANT SELECT ON TABLE ACME_PROVIDER_DB.CUSTOMER_SHARES.NORTHWIND_USAGE_EVENTS TO SHARE NORTHWIND_USAGE_SHARE;
Next, create the external listing:
CREATE EXTERNAL LISTING NORTHWIND_USAGE_LISTING SHARE NORTHWIND_USAGE_SHARE AS $$ title: "Northwind product usage" description: "Live product-usage events for Northwind Retail" open_sharing: catalog_identifier: "northwind-usage" listing_terms: type: "OFFLINE" external_targets: access: - external_consumers: [NORTHWIND_RETAIL] $$;
Here's what the manifest does:
open_sharing.catalog_identifiersets the base name of the catalog that Northwind's Iceberg client connects to. Snowflake appends the listing's global name, so the full catalog name looks likenorthwind-usage-<GLOBAL_NAME>.listing_terms.type: "OFFLINE"means the terms of use are agreed outside Snowflake, for example in Acme's customer contractexternal_targets.access.external_consumersgrants access to theNORTHWIND_RETAILexternal consumer only
Let's confirm the listing exists:
SHOW LISTINGS LIKE 'NORTHWIND_USAGE_LISTING'; DESC LISTING NORTHWIND_USAGE_LISTING;
Finally, get the connection details to send to Northwind:
CALL SYSTEM$GET_LISTING_URL_FOR_EXTERNAL_CONSUMER('NORTHWIND_USAGE_LISTING', 'NORTHWIND_RETAIL');
Copy catalog and catalog_uri from the result. Together with the token secret from the previous step, they're everything Northwind needs. In a real deployment, Acme would send these to Northwind through a secure channel.
Query from Apache Spark
Time to switch roles. You're now Northwind's data engineer, working on your laptop with no Snowflake account. All you have is the catalog name, the catalog URI, and the token that Acme sent you.
Create a file named northwind_query.py. It configures a Spark session with an Iceberg REST catalog that points at the shared listing:
import os from pyspark.sql import SparkSession CATALOG_URI = os.environ["NORTHWIND_CATALOG_URI"] CATALOG_NAME = os.environ["NORTHWIND_CATALOG"] PAT = os.environ["NORTHWIND_PAT"] ICEBERG_VERSION = "1.9.1" spark = ( SparkSession.builder.appName("northwind-usage") .config( "spark.jars.packages", f"org.apache.iceberg:iceberg-spark-runtime-3.5_2.12:{ICEBERG_VERSION}," # For listings served from Azure, use iceberg-azure-bundle instead f"org.apache.iceberg:iceberg-aws-bundle:{ICEBERG_VERSION}", ) .config("spark.sql.extensions", "org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions") .config("spark.sql.iceberg.vectorization.enabled", "false") .config("spark.sql.catalog.acme", "org.apache.iceberg.spark.SparkCatalog") .config("spark.sql.catalog.acme.type", "rest") .config("spark.sql.catalog.acme.uri", CATALOG_URI) .config("spark.sql.catalog.acme.warehouse", CATALOG_NAME) .config("spark.sql.catalog.acme.credential", PAT) .config("spark.sql.catalog.acme.scope", "session:role:external") .config("spark.sql.catalog.acme.header.X-Iceberg-Access-Delegation", "vended-credentials") .getOrCreate() ) spark.sparkContext.setLogLevel("ERROR") spark.sql("SHOW NAMESPACES IN acme").show(truncate=False) spark.sql("SHOW TABLES IN acme.CUSTOMER_SHARES").show(truncate=False) usage = spark.table("acme.CUSTOMER_SHARES.NORTHWIND_USAGE_EVENTS") print(f"Total events: {usage.count()}") (usage.groupBy("feature") .agg({"session_seconds": "avg", "event_id": "count"}) .orderBy("count(event_id)", ascending=False) .show())
Set the three values as environment variables and run the script:
export NORTHWIND_CATALOG_URI="<catalog_uri from Acme>" export NORTHWIND_CATALOG="<catalog from Acme>" export NORTHWIND_PAT="<token_secret from Acme>" python northwind_query.py
The first run downloads the Iceberg runtime packages, so it can take a minute. You should see the shared namespace and table listed, a total of 10,000 events, and the same per-feature breakdown you saw in Snowflake.
Here's what the code does:
- Registers a Spark catalog named
acmethat speaks the Iceberg REST protocol - Authenticates to the catalog with the external consumer's PAT, using the
session:role:externalscope - Turns off Iceberg vectorized reads, which Open Data Sharing tables require. Without this setting, aggregate queries fail.
- Asks the catalog for temporary storage credentials, so Spark can read the Iceberg data files directly
- Lists the shared tables and runs an aggregate query in Spark
Nothing was exported. Spark reads the same Iceberg files that Snowflake manages.
See Live Updates
With a CSV export, new data shows up the next day. With Open Data Sharing, the consumer reads the current snapshot of the table. Let's prove it.
Switch back to Acme. In your Snowsight worksheet, add a burst of new events for a feature Northwind just turned on:
INSERT INTO ACME_PROVIDER_DB.CUSTOMER_SHARES.NORTHWIND_USAGE_EVENTS SELECT 100000 + SEQ4(), CURRENT_TIMESTAMP()::TIMESTAMP_NTZ(6), 'user_' || UNIFORM(1, 250, RANDOM()), 'ai_assistant', UNIFORM(30, 600, RANDOM()) FROM TABLE(GENERATOR(ROWCOUNT => 500));
Now switch back to Northwind and run the script again:
python northwind_query.py
You should see 10,500 total events and a new ai_assistant row in the breakdown. There was no refresh job and no new file drop. The change was visible as soon as the INSERT committed.
Revoke Access
Acme keeps control of the data after it's shared. If a contract ends or a token leaks, Acme can cut off access immediately.
As Acme, remove Northwind's token:
ALTER EXTERNAL CONSUMER NORTHWIND_RETAIL REMOVE PAT northwind_pat; SHOW USER PROGRAMMATIC ACCESS TOKENS FOR EXTERNAL CONSUMER NORTHWIND_RETAIL;
The token list should now be empty. As Northwind, run the script one more time:
python northwind_query.py
This time the script fails while connecting to the catalog with an authentication error. Northwind can no longer read the table.
To restore access, Acme adds a new token and sends Northwind the new secret:
ALTER EXTERNAL CONSUMER NORTHWIND_RETAIL ADD PAT northwind_pat_v2 DAYS_TO_EXPIRY = 7;
Update NORTHWIND_PAT with the new token_secret and rerun the script to confirm it works again.
Clean Up
Let's remove everything the guide created so your account is left clean. Run this as Acme in Snowsight:
USE ROLE OPEN_SHARING_QS_ROLE; -- Unpublish and drop the listing, then drop the share and external consumer ALTER LISTING IF EXISTS NORTHWIND_USAGE_LISTING UNPUBLISH; DROP LISTING IF EXISTS NORTHWIND_USAGE_LISTING; DROP SHARE IF EXISTS NORTHWIND_USAGE_SHARE; DROP EXTERNAL CONSUMER IF EXISTS NORTHWIND_RETAIL; -- Drop guide objects DROP DATABASE IF EXISTS ACME_PROVIDER_DB; DROP WAREHOUSE IF EXISTS OPEN_SHARING_QS_WH; -- Drop the role created for this Quickstart USE ROLE ACCOUNTADMIN; DROP ROLE IF EXISTS OPEN_SHARING_QS_ROLE;
On your laptop, you can delete northwind_query.py and unset the NORTHWIND_CATALOG_URI, NORTHWIND_CATALOG, and NORTHWIND_PAT environment variables.
Conclusion And Resources
You replaced a nightly CSV export with a live, governed share. Acme shared an Iceberg table with a customer who doesn't use Snowflake, Northwind queried it from Apache Spark with nothing but a URL and a token, new data showed up the moment it was written, and Acme revoked access with one command.
If the data you want to share isn't stored as Iceberg, you can materialize it into a dynamic Iceberg table and share that table the same way.
What You Learned
- How Open Data Sharing powered by Apache Polaris™ lets non-Snowflake engines read live Snowflake data over the Iceberg REST Catalog API
- How to create an external consumer and manage its programmatic access tokens
- How to share an Iceberg table through an external listing and retrieve its catalog URL
- How to connect Apache Spark to a shared catalog and query it
- How to revoke and restore a consumer's access
Resources
- Zero-ETL AI & Data Sharing
- Share data with non-Snowflake consumers
- Open Data Sharing overview
- CREATE EXTERNAL CONSUMER
- SYSTEM$GET_LISTING_URL_FOR_EXTERNAL_CONSUMER
- Getting Started with Open and Interoperable Data Product Sharing
- Govern Apache Iceberg Tables for External Engines with Snowflake Horizon
This content is provided as is, and is not maintained on an ongoing basis. It may be out of date with current Snowflake instances