Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,13 @@ jobs:
--no-interactive
snow connection list

- name: Install lstk
run: npm install -g @localstack/lstk

- name: Start LocalStack
uses: LocalStack/setup-localstack@v0.2.4
with:
image-tag: 'latest'
use-pro: 'true'
configuration: LS_LOG=trace
install-awslocal: 'true'
env:
IMAGE_NAME: localstack/snowflake:latest
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
run: lstk start

- name: Install dependencies
run: |
Expand Down
30 changes: 12 additions & 18 deletions .github/workflows/cloud-pods.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,13 @@ jobs:
run: |
make install

- name: Install lstk
run: npm install -g @localstack/lstk

- name: Start LocalStack
uses: LocalStack/setup-localstack@main
with:
image-tag: 'latest'
use-pro: 'true'
configuration: LS_LOG=trace
install-awslocal: 'true'
env:
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
IMAGE_NAME: localstack/snowflake:latest
run: lstk start

- name: Create Snowflake resources
run: |
Expand All @@ -80,13 +77,12 @@ jobs:
env:
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
run: |
message="Cloud Pod created: smart-factory-app on $(date) with workflow run id: ${{ github.run_id }}"
localstack pod save smart-factory-app --message "$message"
lstk snapshot save pod:smart-factory-app

- name: Show LocalStack Logs
if: always()
run: |
localstack logs
lstk logs

test-cloud-pod:
name: Test Cloud Pod
Expand All @@ -96,21 +92,19 @@ jobs:
- name: Checkout Code
uses: actions/checkout@v4

- name: Install lstk
run: npm install -g @localstack/lstk

- name: Start LocalStack
uses: LocalStack/setup-localstack@main
with:
use-pro: 'true'
install-awslocal: 'true'
env:
DEBUG: 1
IMAGE_NAME: localstack/snowflake:latest
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
run: lstk start

- name: Load Cloud Pod
env:
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
run: |
localstack pod load smart-factory-app
lstk snapshot load pod:smart-factory-app

- name: Install dependencies
run: |
Expand All @@ -124,7 +118,7 @@ jobs:
- name: Show LocalStack Logs
if: always()
run: |
localstack logs
lstk logs

- name: Generate a Diagnostic Report
if: failure()
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# LocalStack

volume/
.lstk/lstk.log

# dbt

Expand Down
10 changes: 10 additions & 0 deletions .lstk/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[[containers]]
type = "snowflake"
tag = "latest"
port = "4566"
env = ["ci"]

[env.ci]
DEBUG = "1"
SF_LOG = "trace"
LS_LOG = "trace"
21 changes: 8 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ LATEST ?= false
check: ## Check if all required prerequisites are installed
@echo "Checking if all required prerequisites are installed..."
@which snow > /dev/null 2>&1 || (echo "Snowflake CLI is not installed. Please install it from https://docs.snowflake.com/en/user-guide/snowsql-install-config.html" && exit 1)
@which localstack > /dev/null 2>&1 || (echo "LocalStack is not installed. Please install it from https://docs.localstack.cloud/getting-started/installation/" && exit 1)
@which lstk > /dev/null 2>&1 || (echo "lstk is not installed. Please install it from https://docs.localstack.cloud/aws/developer-tools/running-localstack/lstk/" && exit 1)
@which aws > /dev/null 2>&1 || (echo "AWS CLI is not installed. Please install it from https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html" && exit 1)
@echo python > /dev/null 2>&1 || (echo "Python is not installed. Please install it from https://www.python.org/downloads/" && exit 1)
@echo virtualenv > /dev/null 2>&1 || (echo "virtualenv is not installed. Please install it from https://virtualenv.pypa.io/en/latest/installation.html" && exit 1)
@echo docker > /dev/null 2>&1 || (echo "Docker is not installed. Please install it from https://docs.docker.com/get-docker/" && exit 1)
Expand Down Expand Up @@ -89,13 +90,13 @@ debug: ## Clean up everything and redeploy to fix bugs
snow sql -c localstack -q "USE DATABASE FACTORY_PIPELINE_DEMO; USE SCHEMA PUBLIC; DROP FILE FORMAT IF EXISTS csv_format;"
snow sql -c localstack -q "DROP PIPE IF EXISTS FACTORY_PIPELINE_DEMO.PUBLIC.SENSOR_DATA_PIPE;"
snow sql -c localstack -q "DROP TABLE IF EXISTS FACTORY_PIPELINE_DEMO.PUBLIC_RAW.SENSOR_DATA;"
awslocal s3 rb s3://factory-sensor-data-local --force
lstk aws s3 rb s3://factory-sensor-data-local --force
make deploy
@echo "Debug cleanup and redeploy completed successfully."

alerts: ## Setup alerts
@echo "Setting up alerts..."
awslocal ses verify-email-identity --email hello@example.com
lstk aws ses verify-email-identity --email hello@example.com
snow sql -f solutions/task_alert_udf.sql -c localstack
@echo "Alerts setup successfully."

Expand All @@ -110,23 +111,17 @@ test: ## Run tests
start: ## Start LocalStack
@echo "Starting LocalStack..."
@test -n "${LOCALSTACK_AUTH_TOKEN}" || (echo "LOCALSTACK_AUTH_TOKEN is not set. Find your token at https://app.localstack.cloud/workspace/auth-token"; exit 1)
DOCKER_FLAGS='-e SF_LOG=trace' \
DEBUG=1 \
IMAGE_NAME=localstack/snowflake:latest \
LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN) \
localstack start -d
lstk start
@echo "LocalStack started successfully."

stop: ## Stop LocalStack
@echo "Stopping LocalStack..."
@localstack stop
@lstk stop
@echo "LocalStack stopped successfully."

ready: ## Make sure the LocalStack container is up
@echo Waiting on the LocalStack container...
@localstack wait -t 30 && echo LocalStack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1)

logs: ## Save the logs in a separate file
@localstack logs > logs.txt
@lstk logs > logs.txt

.PHONY: install seed aws upload pipeline dbt app deploy test start stop ready logs debug generate
.PHONY: install seed aws upload pipeline dbt app deploy test start stop logs debug generate
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ The application implements a modern data pipeline architecture showcasing a real

## Prerequisites

- A valid [LocalStack for Snowflake license](https://localstack.cloud/pricing). Your license provides a [`LOCALSTACK_AUTH_TOKEN`](https://docs.localstack.cloud/getting-started/auth-token/) to activate LocalStack.
- A valid [LocalStack for Snowflake license](https://localstack.cloud/pricing). Your license provides a [`LOCALSTACK_AUTH_TOKEN`](https://docs.localstack.cloud/aws/getting-started/auth-token/) to activate LocalStack.
- [Docker](https://docs.docker.com/get-docker/)
- [`localstack` CLI](https://docs.localstack.cloud/getting-started/installation/#localstack-cli).
- [AWS CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/) with the [`awslocal` wrapper](https://docs.localstack.cloud/user-guide/integrations/aws-cli/#localstack-aws-cli-awslocal).
- [`lstk` CLI](https://docs.localstack.cloud/aws/developer-tools/running-localstack/lstk/). The [AWS CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/) is required by `lstk aws`.
- [Snowflake CLI](https://docs.snowflake.com/developer-guide/snowflake-cli/index) with a [`localstack` connection profile](https://snowflake.localstack.cloud/user-guide/integrations/snow-cli/).
- [Python](https://www.python.org/downloads/) 3.10+ & [`pip`](https://pip.pypa.io/en/stable/installation/)
- [`make`](https://www.gnu.org/software/make/) (**optional**, but recommended for running the sample application)
Expand Down Expand Up @@ -59,11 +58,8 @@ make install
Start LocalStack with the `LOCALSTACK_AUTH_TOKEN` pre-configured:

```bash
localstack auth set-token <your-auth-token>
DOCKER_FLAGS='-e SF_LOG=trace' \
DEBUG=1 \
IMAGE_NAME=localstack/snowflake:latest \
localstack start
export LOCALSTACK_AUTH_TOKEN=<your-auth-token>
lstk start
```

To deploy the sample application, run the following command:
Expand Down Expand Up @@ -186,14 +182,14 @@ Cloud Pods enable persistent state snapshots of your LocalStack instance that ca
To save a Cloud Pod, run the following command:

```bash
localstack pod save smart-factory-app
lstk snapshot save pod:smart-factory-app
```

To load a Cloud Pod, run the following command:

```bash
# Restore the saved state in a fresh LocalStack instance
localstack pod load smart-factory-app
lstk snapshot load pod:smart-factory-app
```

The key advantages are:
Expand Down
3 changes: 3 additions & 0 deletions setup/01_setup_snowflake.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
-- Create the warehouse the connection profile references
CREATE WAREHOUSE IF NOT EXISTS TEST;

-- Create and use database
CREATE DATABASE IF NOT EXISTS FACTORY_PIPELINE_DEMO;
USE DATABASE FACTORY_PIPELINE_DEMO;
Expand Down
Loading