Initialization Hooks
2 minute read
LocalStack's Snowflake emulator is currently in preview mode. We will be launching our general availability product for purchase on May 13th, 2025. Interested in learning more? Visit our site.
Note: Version 0.3.0 and beyond are only available to customers who have been granted a Snowflake license from LocalStack. If you accessed Snowflake via your AWS Emulator without a Snowflake license in prior versions, please reach out to us here.
Introduction
LocalStack for Snowflake supports automatically executing *.sf.sql
files via Init Hooks when mounted into the Docker container. A script can be added to one of these stages in the lifecycle:
BOOT
: the container is running, but LocalStack hasn’t startedSTART
: the Python process is running, and LocalStack is startingREADY
: LocalStack is ready for requestsSHUTDOWN
: LocalStack is shutting down
A script can be in one of four states: UNKNOWN
, RUNNING
, SUCCESSFUL
, or ERROR
. By default, scripts are in the UNKNOWN
state when first discovered.
Getting started
To begin, create a script called test.sf.sql
with the following SQL statements:
CREATE DATABASE foobar123;
CREATE DATABASE test123;
SHOW DATABASES;
Mount the script into /etc/localstack/init/ready.d/
using Docker Compose or the localstack
CLI:
version: "3.8"
services:
localstack:
container_name: "${LOCALSTACK_DOCKER_NAME:-localstack-main}"
image: localstack/snowflake
ports:
- "127.0.0.1:4566:4566"
- "127.0.0.1:4510-4559:4510-4559"
- "127.0.0.1:443:443"
environment:
- LOCALSTACK_AUTH_TOKEN=${LOCALSTACK_AUTH_TOKEN:?}
- DEBUG=1
volumes:
- "/path/to/test.sf.sql:/etc/localstack/init/ready.d/test.sf.sql" # ready hook
- "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"
# DOCKER_FLAGS are additional parameters to the `docker run` command of localstack start
DOCKER_FLAGS='-v /path/to/test.sf.sql:/etc/localstack/init/ready.d/test.sf.sql' DEBUG=1 localstack start
Start the Snowflake emulator, and the following logs will appear:
DEBUG --- [et.reactor-0] s.analytics.handler : REQ: POST /queries/v1/query-request {"sqlText": "CREATE DATABASE foobar123", ...
DEBUG --- [et.reactor-0] s.analytics.handler : REQ: POST /queries/v1/query-request {"sqlText": "CREATE DATABASE test123", ...
DEBUG --- [et.reactor-0] s.analytics.handler : REQ: POST /queries/v1/query-request {"sqlText": "SHOW DATABASES", ...