External Functions are scalar functions that let Snowflake SQL queries call external REST APIs through a cloud provider's API Gateway. By placing AWS Lambda, Azure Functions, or Google Cloud Functions on the backend, you can complete ML inference, data enrichment, and external service integrations entirely within SQL.
SELECT external_func(col) FROM table
│
├─ Snowflake Virtual Warehouse
│ └─ batches the input rows into JSON
│
├─ Cloud Services Layer
│ └─ calls API Gateway with the API Integration credentials
│
├─ API Gateway (AWS API Gateway / Azure APIM / GCP API Gateway)
│ └─ authentication, rate limiting, routing
│
└─ Backend (Lambda / Azure Functions / Cloud Functions)
└─ runs the business logic -> returns JSON-- The request format Snowflake sends
{
"data": [
[0, "Hello world"],
[1, "Snowflake is great"],
[2, "External functions rock"]
]
}
-- The response format your backend must return
{
"data": [
[0, "positive"],
[1, "positive"],
[2, "positive"]
]
}Each row is an array of [row_number, value...]. Snowflake assigns the row number automatically, and the response must return the same row numbers. Backend code parses this format and returns results in the same shape.
# AWS Lambda function (Python)
import json
def lambda_handler(event, context):
body = json.loads(event['body'])
rows = body['data']
results = []
for row in rows:
row_number = row[0]
input_text = row[1]
# Business logic: return the character count of the text
char_count = len(input_text) if input_text else 0
results.append([row_number, char_count])
return {
'statusCode': 200,
'body': json.dumps({'data': results})
}-- Assumes the API Integration already exists
-- (see the API Integrations article for CREATE API INTEGRATION details)
CREATE OR REPLACE EXTERNAL FUNCTION char_count(input_text VARCHAR)
RETURNS INT
API_INTEGRATION = aws_ml_api
MAX_BATCH_ROWS = 500
AS 'https://abc123.execute-api.us-east-1.amazonaws.com/prod/char-count';CREATE OR REPLACE EXTERNAL FUNCTION translate_text(text VARCHAR, target_lang VARCHAR)
RETURNS VARCHAR
API_INTEGRATION = azure_translate_api
AS 'https://my-apim.azure-api.net/translate/v1';CREATE OR REPLACE EXTERNAL FUNCTION geocode_address(address VARCHAR)
RETURNS VARIANT
API_INTEGRATION = gcp_geocode_api
AS 'https://my-gateway-abc123.uc.gateway.dev/geocode';| Component | AWS | Azure | GCP |
|---|---|---|---|
| API Gateway | Amazon API Gateway | Azure API Management | Google Cloud API Gateway |
| Backend | Lambda | Azure Functions | Cloud Functions |
| API_PROVIDER | aws_api_gateway | azure_api_management | google_api_gateway |
| Authentication | IAM Role + STS | Azure AD | Service Account |
-- A basic call
SELECT id, text, char_count(text) AS count
FROM documents
LIMIT 1000;
-- Call it conditionally with a CASE expression (cost optimization)
SELECT
id,
text,
CASE
WHEN needs_translation = TRUE
THEN translate_text(text, 'ja')
ELSE text
END AS translated_text
FROM documents;
-- Persist the result
CREATE TABLE enriched_documents AS
SELECT
d.*,
geocode_address(d.address) AS geo_result,
geo_result:lat::FLOAT AS latitude,
geo_result:lng::FLOAT AS longitude
FROM documents d
WHERE d.address IS NOT NULL;| Parameter | Default | Description |
|---|---|---|
| MAX_BATCH_ROWS | Auto | Maximum rows per request. Tune to match backend timeout constraints. |
| COMPRESSION | AUTO | Request/response compression. You can disable it with NONE for large data transfers. |
| REQUEST_TRANSLATOR / RESPONSE_TRANSLATOR | None | Specify custom request/response transformation functions. |
External Functions
Question 1
Which JSON format correctly represents the request that the External Function backend (AWS Lambda) must handle?
Correct answer: B
Snowflake External Functions send requests in the format {"data": [[row_number, arg1, arg2, ...], ...]}. Each row is an array whose first element is the row number (zero-based), followed by the function arguments. The response must use the same format. This is a Snowflake-specific protocol, and backend implementations must parse it explicitly.
Can I control the batch size when calling an External Function?
Yes — use the MAX_BATCH_ROWS parameter to control the maximum number of rows per HTTP request. By default Snowflake automatically determines the optimal batch size, but if your backend Lambda/Cloud Functions have tight timeout or memory constraints, set a smaller explicit value such as MAX_BATCH_ROWS = 100. Smaller batches increase the number of HTTP requests, so there is a trade-off with latency.
Are External Functions synchronous or asynchronous?
Synchronous by default. Snowflake sends the request to the backend and blocks query execution until the response arrives. Watch out for API Gateway timeouts when backend processing is long (AWS API Gateway defaults to 29 seconds). If you need to exceed that timeout, implement an asynchronous pattern on the backend (e.g., SQS + Lambda) and have API Gateway poll for results.
What is the JSON format for External Function requests and responses?
Requests follow the format {"data": [[0, arg1, arg2], [1, arg3, arg4], ...]}, where each row is an array of [row_number, arg1, arg2, ...]. Responses must use the same shape: {"data": [[0, result1], [1, result2], ...]}, returning an array of row numbers and result values. Backend Lambda/Cloud Functions code must parse this format on input and produce it on output.
Practice with certification-focused question sets
Try free questionsNicheeLab Editorial Team
NicheeLab editorial team focused on data engineering and cloud certification learning. Content is structured around practical study needs and official exam domains.
Snowflake Certifications: All 11 Exams Explained (2026)
Every SnowPro certification — Associate, Core, Specialty, Ad...
Snowflake Exam Difficulty Ranking: All 11 Certs Compared (2026)
All 11 SnowPro exams ranked by difficulty with study-time es...
Snowflake Study Guide: Fastest Pass Route by Exam (2026)
How to pass SnowPro certifications efficiently — official ma...
SnowPro Core (COF-C03): Complete Exam Guide (2026)
Pass the SnowPro Core exam — six domains, scope, sample ques...
SnowPro Associate Platform (SOL-C01): Complete Guide (2026)
The entry-level SnowPro Associate exam — scope, weighting, s...