In this post we are going to cover reaching outside Snowflake from a function.
Everything we have written in this course so far has stayed inside the account. A function reads tables, works something out, and hands back a value. So what does it take to call something that is not in the account at all?
The short answer is that it is never a property of your function. It is always a separate object that somebody with the rights has to create and name, and your function is then allowed to use it. There are two of those objects, one old and one current, and on a trial account one of them is not available at all.
We will start with a function that stays inside and build it up step by step. Every query below was run on a real Snowflake account, and every result you see is the output it gave back.
Episode 154 of the Snowflake SQL: Zero to Hero series on TechBrothersIT.
- Let's create some sample data
- Let's see what this account already has
- Let's start with a function that stays inside Snowflake
- Now let's try it the naive way, from Python
- So let's try the older way: an API integration
- Four refusals, and only two of them are answers
- Now a rule you really can make
- And the one object a trial account cannot have
- One last thing: let's put the account back
Let's create some sample data
We need something to pass through the functions, so the script below makes a small table of cities.
-- Sample data for this post.
-- A tiny table of cities, so the functions have something to be called with.
USE DATABASE DEMO_DB;
USE SCHEMA PUBLIC;
CREATE OR REPLACE TABLE CITIES_T154 (
CITY_ID INT,
CITY_NAME VARCHAR(20),
COUNTRY VARCHAR(20)
);
INSERT INTO CITIES_T154 (CITY_ID, CITY_NAME, COUNTRY) VALUES
(1, 'Karachi', 'Pakistan'),
(2, 'Lahore', 'Pakistan'),
(3, 'Dubai', 'UAE'),
(4, 'Toronto', 'Canada');INSERT INTO CITIES_T154 (CITY_ID, CITY_NAME, COUNTRY)
VALUES (1, 'Karachi', 'Pakistan'), (2, 'Lahore', 'Pakistan'),
(3, 'Dubai', 'UAE'), (4, 'Toronto', 'Canada');| number of rows inserted |
|---|
| 4 |
And here is what that leaves in the table.
SELECT * FROM CITIES_T154 ORDER BY CITY_ID;| CITY_ID | CITY_NAME | COUNTRY |
|---|---|---|
| 1 | Karachi | Pakistan |
| 2 | Lahore | Pakistan |
| 3 | Dubai | UAE |
| 4 | Toronto | Canada |
Four cities and three columns. That is the whole data set for this post, because the episode is about objects rather than rows.
Let's see what this account already has
This episode makes integrations, so before anything else let's ask what integrations are already here.
SHOW INTEGRATIONS;| name | type | category | enabled | comment | created_on |
|---|---|---|---|---|---|
| SNOWFLAKE$LOCAL_APPLICATION | OAUTH - LOCAL_APPLICATION | SECURITY | true | https://docs.snowflake.com/user-guide/oauth-local-application | 2026-09-21 18:33:42.250000-07:00 |
One row, and it is not mine. Snowflake created SNOWFLAKE$LOCAL_APPLICATION itself, for OAuth. Remember that row, because the last grid of this post shows that exact row and nothing else.
Now the other kind of object we are going to need.
SHOW NETWORK RULES;| created_on | name | database_name | schema_name | owner | comment | type | mode | entries_in_valuelist | owner_role_type |
|---|
No network rules at all. So we are starting from a clean account.
And this is where the session is pointing while all of this runs.
SELECT CURRENT_DATABASE() AS THE_DATABASE,
CURRENT_SCHEMA() AS THE_SCHEMA,
CURRENT_ROLE() AS THE_ROLE,
CURRENT_VERSION() AS THE_VERSION;| THE_DATABASE | THE_SCHEMA | THE_ROLE | THE_VERSION |
|---|---|---|---|
| DEMO_DB | PUBLIC | ACCOUNTADMIN | 10.35.101 |
The role matters in this episode. ACCOUNTADMIN is the role that is allowed to create integrations, so nothing below is going to fail for want of a privilege.
Let's start with a function that stays inside Snowflake
Here is a plain SQL function. It upper-cases whatever you give it and adds an exclamation mark.
CREATE OR REPLACE FUNCTION SHOUT_T154(S VARCHAR)
RETURNS VARCHAR
LANGUAGE SQL
AS
$$
UPPER(S) || '!'
$$;| status |
|---|
| Function SHOUT_T154 successfully created. |
And here it is, called over our four cities.
SELECT CITY_NAME, SHOUT_T154(CITY_NAME) AS SHOUTED
FROM CITIES_T154 ORDER BY CITY_ID;| CITY_NAME | SHOUTED |
|---|---|
| Karachi | KARACHI! |
| Lahore | LAHORE! |
| Dubai | DUBAI! |
| Toronto | TORONTO! |
That works, and it never leaves the account. Everything it needed was already in here.
So here is the question for the whole post. What would it take to call something that is not in here?
Now let's try it the naive way, from Python
The obvious thing to try is a Python function that just makes an HTTP request. Let's write one and see what stops us.
CREATE OR REPLACE FUNCTION REACH_OUT_T154(HOSTNAME VARCHAR)
RETURNS VARCHAR
LANGUAGE PYTHON
RUNTIME_VERSION = '3.11'
PACKAGES = ('requests')
HANDLER = 'go'
AS
$$
import requests
def go(hostname):
r = requests.get('https://' + hostname + '/', timeout=5)
return 'status ' + str(r.status_code)
$$;| status |
|---|
| Function REACH_OUT_T154 successfully created. |
Created successfully. Nothing stopped us writing that and nothing even warned us, so the refusal is going to arrive later.
Now let's call it, pointed at example.com.
SELECT REACH_OUT_T154('example.com') AS WHAT_CAME_BACK;100357 (P0000): Failed to connect to host='example.com', port=443. Please verify url is present in the network rule. Error in function REACH_OUT_T154 with handler go
100357, failed to connect. And read the rest of that line, because it is doing us a favour: please verify url is present in the network rule. It is naming the thing we have not got.
Nothing left the account either. The sandbox stopped the request before it was made.
Let's ask the same question a second way, in case that was about the requests package. A plain socket from the standard library, straight at port 443.
CREATE OR REPLACE FUNCTION REACH_OUT_PLAIN_T154(HOSTNAME VARCHAR)
RETURNS VARCHAR
LANGUAGE PYTHON
RUNTIME_VERSION = '3.11'
HANDLER = 'go'
AS
$$
import socket
def go(hostname):
s = socket.create_connection((hostname, 443), timeout=5)
s.close()
return 'the socket opened'
$$;| status |
|---|
| Function REACH_OUT_PLAIN_T154 successfully created. |
SELECT REACH_OUT_PLAIN_T154('example.com') AS WHAT_CAME_BACK;100357 (P0000): Python Interpreter Error:
Traceback (most recent call last):
File "_udf_code.py", line 5, in go
s = socket.create_connection((hostname, 443), timeout=5)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<stdlib>/socket.py", line 839, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<stdlib>/socket.py", line 974, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 16] Device or resource busy
in function REACH_OUT_PLAIN_T154 with handler goA Python traceback this time, and look at where it actually failed. Inside getaddrinfo. It could not even resolve the name, let alone connect to it.
So a function cannot open a socket. That is the design, not something somebody forgot.
So let's try the older way: an API integration
The older of the two mechanisms is an API integration pointed at a cloud gateway, with an external function on top of it. Let's create the integration, and look at the role ARN I gave it: that role does not exist. I wanted to know whether it checks.
CREATE OR REPLACE API INTEGRATION GATEWAY_T154
API_PROVIDER = aws_api_gateway
API_AWS_ROLE_ARN = 'arn:aws:iam::123456789012:role/no-such-role-t154'
API_ALLOWED_PREFIXES = ('https://example.com/snowflake/')
ENABLED = TRUE;002157 (42601): SQL compilation error: URL 'https://example.com/snowflake/' is invalid. Make sure the URL host is reachable and that the URL is for Amazon API Gateway service.
002157, and this is not the answer I was expecting. Read what it checked. The URL. It never got as far as my made-up role at all.
So CREATE API INTEGRATION validates the URL at create time, which is a more useful thing to know than what I was asking.
Did anything get created? Let's ask for integrations whose name ends in _T154.
SHOW INTEGRATIONS LIKE '%\\_T154';| name | type | category | enabled | comment | created_on |
|---|
Nothing. So the create really did fail and left nothing behind. That is going to cost us something in the next section, so it is worth being clear about it now.
Here is the external function that was going to use that integration.
CREATE OR REPLACE EXTERNAL FUNCTION TRANSLATE_T154(WORD VARCHAR)
RETURNS VARIANT
API_INTEGRATION = GATEWAY_T154
AS 'https://example.com/snowflake/translate';002003 (02000): SQL compilation error: Integration 'GATEWAY_T154' does not exist or not authorized. Your primary role ACCOUNTADMIN or one of your secondary roles must have at least one privilege granted on INTEGRATION GATEWAY_T154.
002003, integration GATEWAY_T154 does not exist. Which is perfectly true. It never existed, because the statement above it failed.
SHOW EXTERNAL FUNCTIONS LIKE '%\\_T154';| created_on | name | schema_name | is_builtin | is_aggregate | is_ansi | min_num_arguments | max_num_arguments | arguments | description | catalog_name | is_table_function | valid_for_clustering | is_secure | secrets | external_access_integrations | is_external_function | language | is_memoizable | is_data_metric | is_ai_function |
|---|
And nothing was made here either.
Four refusals, and only two of them are answers
I wrote four deliberately broken external functions to get four refusals on screen. Two of them answered the question they were asked. Two of them did not, and I would rather say so than let four grids look like something they are not.
Here is the first. No API_INTEGRATION clause at all.
CREATE OR REPLACE EXTERNAL FUNCTION NOINT_T154(WORD VARCHAR)
RETURNS VARIANT
AS 'https://example.com/snowflake/translate';001480 (42601): Property 'API_INTEGRATION' must be specified
001480, property API_INTEGRATION must be specified. That is a real answer. The clause is mandatory and the message says so in plain words.
Second, an integration name that was never anything, to see what that error looks like.
CREATE OR REPLACE EXTERNAL FUNCTION NOSUCHINT_T154(WORD VARCHAR)
RETURNS VARIANT
API_INTEGRATION = NO_SUCH_GATEWAY_T154
AS 'https://example.com/snowflake/translate';002003 (02000): SQL compilation error: Integration 'NO_SUCH_GATEWAY_T154' does not exist or not authorized. Your primary role ACCOUNTADMIN or one of your secondary roles must have at least one privilege granted on INTEGRATION NO_SUCH_GATEWAY_T154.
002003, quoting my made-up name back at me. Also a real answer.
And now the two that are not answers
The third one leaves the URL off the end, and I wanted to see the complaint about the missing URL.
CREATE OR REPLACE EXTERNAL FUNCTION NOURL_T154(WORD VARCHAR)
RETURNS VARIANT
API_INTEGRATION = GATEWAY_T154;002003 (02000): SQL compilation error: Integration 'GATEWAY_T154' does not exist or not authorized. Your primary role ACCOUNTADMIN or one of your secondary roles must have at least one privilege granted on INTEGRATION GATEWAY_T154.
002003, integration GATEWAY_T154 does not exist. That is not an answer about a missing URL. It died on the missing integration first, before it ever looked at the end of the statement.
And the fourth puts a SQL body where the URL goes, which fails the same way for the same reason.
CREATE OR REPLACE EXTERNAL FUNCTION NOTEXTERNAL_T154(WORD VARCHAR)
RETURNS VARIANT
API_INTEGRATION = GATEWAY_T154
AS
$$
UPPER(WORD)
$$;002003 (02000): SQL compilation error: Integration 'GATEWAY_T154' does not exist or not authorized. Your primary role ACCOUNTADMIN or one of your secondary roles must have at least one privilege granted on INTEGRATION GATEWAY_T154.
A refusal that fires for the wrong reason teaches you nothing. It just looks like it did. Both of those grids are real output and both are useless as answers about the thing I was testing, because the integration they name was never created. If you want to know what Snowflake says about an external function with no URL, you have to ask it with a real integration in place.
And since none of those functions were created, calling one goes exactly as you would expect.
SELECT NOSUCHINT_T154('hello') AS WHAT_CAME_BACK;002139 (02000): SQL compilation error: Unknown function NOSUCHINT_T154.
002139, unknown function. The old path needs a real cloud gateway behind it, and on this account there is not one.
Now a rule you really can make
The current mechanism is two objects instead of one. The first is a network rule, which names what may be reached. One type, one mode, and one host and port.
CREATE OR REPLACE NETWORK RULE EGRESS_T154
TYPE = HOST_PORT
MODE = EGRESS
VALUE_LIST = ('example.com:443')
COMMENT = 'episode 154 - never called';| status |
|---|
| Network rule EGRESS_T154 is created. |
Created, on a plain account, with no cloud anything. Let's check it is really there.
SHOW NETWORK RULES LIKE '%\\_T154';| created_on | name | database_name | schema_name | owner | comment | type | mode | entries_in_valuelist | owner_role_type |
|---|---|---|---|---|---|---|---|---|---|
| 2026-10-06 08:04:04.852000-07:00 | EGRESS_T154 | DEMO_DB | PUBLIC | ACCOUNTADMIN | episode 154 - never called | HOST_PORT | EGRESS | 1 | ROLE |
One row. The type is HOST_PORT, the mode is EGRESS, and entries_in_valuelist says how many entries the rule holds.
DESCRIBE says the same thing with a little more detail.
DESCRIBE NETWORK RULE EGRESS_T154;| created_on | name | database_name | schema_name | owner | comment | type | mode | value_list |
|---|---|---|---|---|---|---|---|---|
| 2026-10-06 08:04:04.852000-07:00 | EGRESS_T154 | DEMO_DB | PUBLIC | ACCOUNTADMIN | episode 154 - never called | HOST_PORT | EGRESS | example.com:443 |
DESCRIBE gives us the value_list itself, which is the one column SHOW only counts. So that half of the mechanism works and it costs nothing.
Now one deliberate mistake, before we go on to the second object. A mode that does not exist.
CREATE OR REPLACE NETWORK RULE BADMODE_T154
TYPE = HOST_PORT
MODE = SIDEWAYS
VALUE_LIST = ('example.com:443');098511 (22023): SQL compilation error: The network rule mode INGRESS is not supported by the network rule type HOST_PORT. The network rule mode must be one of [EGRESS, DATA_CONNECTIVITY_PROXY_EGRESS].
098511, and read it closely, because something is odd. The message talks about INGRESS. I did not write INGRESS. I wrote SIDEWAYS, a nonsense word.
So this is not an answer about my typo at all. What it actually handed over is the legal mode list for a HOST_PORT rule, which is better than the answer I was after and narrower than the list I would have guessed. I will take the list, and I will not pretend it told me what happened to my made-up word.
And the one object a trial account cannot have
The second object is an external access integration, which allows one or more of those rules. Let's create one that allows the rule we just made.
CREATE OR REPLACE EXTERNAL ACCESS INTEGRATION ACCESS_T154
ALLOWED_NETWORK_RULES = (EGRESS_T154)
ENABLED = TRUE
COMMENT = 'episode 154 - never called';509009 (0A000): SQL compilation error: External access is not supported for trial accounts.
509009. External access is not supported for trial accounts. One line, and that is the whole wall. It is also a perfectly honest refusal: it does not pretend the problem is something I wrote.
SHOW EXTERNAL ACCESS INTEGRATIONS LIKE '%\\_T154';| name | type | category | enabled | comment | created_on |
|---|
DESCRIBE EXTERNAL ACCESS INTEGRATION ACCESS_T154;002003 (02000): SQL compilation error: Integration 'ACCESS_T154' does not exist or not authorized. Your primary role ACCOUNTADMIN or one of your secondary roles must have at least one privilege granted on INTEGRATION ACCESS_T154.
Nothing was created, and DESCRIBE on it is just 002003 confirming that.
And it is the same whichever way we ask. Here it is naming a rule that does not exist either.
CREATE OR REPLACE EXTERNAL ACCESS INTEGRATION BADRULE_T154
ALLOWED_NETWORK_RULES = (NO_SUCH_RULE_T154)
ENABLED = TRUE;509009 (0A000): SQL compilation error: External access is not supported for trial accounts.
509009 again. It does not even get as far as looking for the rule.
Now the Python function from earlier, this time with EXTERNAL_ACCESS_INTEGRATIONS on it.
CREATE OR REPLACE FUNCTION REACH_OUT_ALLOWED_T154(HOSTNAME VARCHAR)
RETURNS VARCHAR
LANGUAGE PYTHON
RUNTIME_VERSION = '3.11'
PACKAGES = ('requests')
HANDLER = 'go'
EXTERNAL_ACCESS_INTEGRATIONS = (ACCESS_T154)
AS
$$
import requests
def go(hostname):
r = requests.get('https://' + hostname + '/', timeout=5)
return 'status ' + str(r.status_code)
$$;509009 (0A000): SQL compilation error: External access is not supported for trial accounts.
The same 509009, which means that function was never created.
SHOW USER FUNCTIONS LIKE 'REACH\\_OUT\\_ALLOWED\\_T154';| created_on | name | schema_name | is_builtin | is_aggregate | is_ansi | min_num_arguments | max_num_arguments | arguments | description | catalog_name | is_table_function | valid_for_clustering | is_secure | secrets | external_access_integrations | is_external_function | language | is_memoizable | is_data_metric | is_ai_function |
|---|
SELECT GET_DDL('FUNCTION', 'DEMO_DB.PUBLIC.REACH_OUT_ALLOWED_T154(VARCHAR)')
AS THE_DEFINITION;002001 (02000): SQL compilation error: Object 'DEMO_DB.PUBLIC.REACH_OUT_ALLOWED_T154(VARCHAR)' does not exist or not authorized.
Empty, and then 002001, the object does not exist. Both of those follow from the refusal above rather than telling us anything new.
A function naming an access integration that was never made gets the same wall.
CREATE OR REPLACE FUNCTION BADACCESS_T154(HOSTNAME VARCHAR)
RETURNS VARCHAR
LANGUAGE PYTHON
RUNTIME_VERSION = '3.11'
HANDLER = 'go'
EXTERNAL_ACCESS_INTEGRATIONS = (NO_SUCH_ACCESS_T154)
AS
$$
def go(hostname):
return 'never runs'
$$;509009 (0A000): SQL compilation error: External access is not supported for trial accounts.
So on this account the trial-account refusal comes first, every time, and we never find out what Snowflake would have said about the made-up name.
One more, and this one is a real answer. EXTERNAL_ACCESS_INTEGRATIONS on a plain SQL function.
CREATE OR REPLACE FUNCTION SQLACCESS_T154(S VARCHAR)
RETURNS VARCHAR
LANGUAGE SQL
EXTERNAL_ACCESS_INTEGRATIONS = (ACCESS_T154)
AS
$$
UPPER(S)
$$;001420 (22023): SQL compilation error: invalid property 'EXTERNAL_ACCESS_INTEGRATIONS' for 'FUNCTION'
001420, invalid property. That is a different refusal from the trial-account one, and it is about the statement rather than the account. The clause is not for SQL bodies at all.
So the rule yes, and the integration no. That is exactly how far a trial account gets you. If you are following along on one, the network rule in the section above will create for you and the integration in this section will not, and 509009 is the line you will see.
One last thing: let's put the account back
Everything this post made is dropped here. The drops that matter are the rule and the table, because they are the only two things that were really created.
DROP NETWORK RULE IF EXISTS DEMO_DB.PUBLIC.EGRESS_T154;| status |
|---|
| EGRESS_T154 successfully dropped. |
DROP TABLE IF EXISTS DEMO_DB.PUBLIC.CITIES_T154;| status |
|---|
| CITIES_T154 successfully dropped. |
And now the grids that prove it. First, integrations.
SHOW INTEGRATIONS;| name | type | category | enabled | comment | created_on |
|---|---|---|---|---|---|
| SNOWFLAKE$LOCAL_APPLICATION | OAUTH - LOCAL_APPLICATION | SECURITY | true | https://docs.snowflake.com/user-guide/oauth-local-application | 2026-09-21 18:33:42.250000-07:00 |
That same single row Snowflake put there, and nothing else. Compare it with the first grid in this post: it is the same row.
SHOW NETWORK RULES;| created_on | name | database_name | schema_name | owner | comment | type | mode | entries_in_valuelist | owner_role_type |
|---|
SELECT CURRENT_DATABASE() AS THE_DATABASE,
CURRENT_SCHEMA() AS THE_SCHEMA,
CURRENT_TRANSACTION() AS ANY_OPEN_TRANSACTION;| THE_DATABASE | THE_SCHEMA | ANY_OPEN_TRANSACTION |
|---|---|---|
| DEMO_DB | PUBLIC | NULL |
No rules, and no open transaction. CURRENT_TRANSACTION() returning NULL is how you know nothing was left half done.
SELECT COUNT(*) AS PROBE_OBJECTS_LEFT
FROM DEMO_DB.INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'PUBLIC' AND ENDSWITH(TABLE_NAME, '_T154');| PROBE_OBJECTS_LEFT |
|---|
| 0 |
SELECT COUNT(*) AS PROBE_FUNCTIONS_LEFT
FROM DEMO_DB.INFORMATION_SCHEMA.FUNCTIONS
WHERE FUNCTION_SCHEMA = 'PUBLIC' AND ENDSWITH(FUNCTION_NAME, '_T154');| PROBE_FUNCTIONS_LEFT |
|---|
| 0 |
No tables of mine and no functions of mine. The account is exactly as we found it.
Nothing in this post sent a byte to any server. Every hostname is example.com, which IANA reserves for documentation precisely so that nobody's real server is on the end of it. The only network-touching function that is actually called is the one with no integration attached, whose entire point is that the sandbox stops it first.
Key points
- Reaching outside is never a clause in your function. It is a separate object somebody creates and names, and your function is then allowed to use it.
- A Python function that tries to connect is created without a word of complaint and fails when it is called, with
100357, and the message names the network rule you are missing. - A plain socket inside a function cannot even resolve a hostname. It fails inside
getaddrinfo. CREATE API INTEGRATIONvalidates the URL before it looks at the role, which is002157here.API_INTEGRATIONis mandatory on an external function, which is001480.- Two of the four external function refusals died on the missing integration first, so they are not answers about the thing they were testing.
- A
NETWORK RULEcreates on a plain account, andDESCRIBEshows you thevalue_listthatSHOWonly counts. - An error about a mode nobody typed still handed over the legal mode list for
HOST_PORT. CREATE EXTERNAL ACCESS INTEGRATIONis509009on a trial account, in one plain line, whichever way you ask.EXTERNAL_ACCESS_INTEGRATIONSon aSQLfunction is refused outright with001420, which is a different refusal entirely.
That is Level 12 finished. In the next post we start Level 13 with warehouses: what CREATE WAREHOUSE with nothing but a name gives you, and the thing it does that the statement never mentions.
Every query and every result grid on this page was captured from a live Snowflake account (version 10.35.101) running the demo script for this episode. The account is a trial account, which is why 509009 appears, and the post says so rather than presenting that refusal as universal. Every hostname is example.com and no request ever left the account. Everything created here is dropped here. Nothing is timed and no performance claims are made anywhere in this series. Behaviour follows the Snowflake external access documentation.



No comments:
Post a Comment
Note: Only a member of this blog may post a comment.