Calling out to an external service from Snowflake with external functions
External functions let Snowflake call out to code running outside its environment (e.g., a cloud provider's serverless compute) via a remote HTTPS endpoint, extending SQL with custom logic that can't be expressed natively. They are defined with CREATE EXTERNAL FUNCTION and rely on an API integration object to securely route requests through a proxy service to the remote endpoint.
1 · Learn the must-know
- An API integration must be created first (CREATE API INTEGRATION) to define the trusted proxy service and allowed endpoint prefixes before an external function can reference it.
- External functions are always scalar: they return exactly one value per input row and cannot be defined as aggregate or table functions.
- Snowflake batches multiple rows into a single HTTPS request/response for efficiency; the remote service must handle the JSON array-of-arrays format Snowflake sends and return results in the same row order.
- The remote service (e.g., a cloud function or Lambda) is invoked over HTTPS through the API Gateway/proxy configured in the API integration, and it must return a well-formed JSON response or the query fails.
- Because each call involves network round-trips, external functions add latency and cost compared to native UDFs/UDTFs, so they should be reserved for logic that truly cannot be done inside Snowflake.
- CREATE EXTERNAL FUNCTION requires specifying the API integration, the remote service URL (AS), and can optionally set
MAX_BATCH_ROWSto control batch size sent per HTTP call.
3 · Keep going
Ready for more? Take a weighted mock or try free practice questions.