Skip to content

Commit 875c7be

Browse files
authored
Migrate from the localstack CLI to lstk (#85)
1 parent 2071a6d commit 875c7be

5 files changed

Lines changed: 36 additions & 62 deletions

File tree

.github/workflows/integration-test.yml

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,10 @@ jobs:
3535
ruby-version: '3.3'
3636
working-directory: demo/lambdas/ruby
3737

38-
- name: Setup LocalStack
39-
uses: localstack/setup-localstack@main
40-
with:
41-
image-tag: 'latest'
42-
use-pro: 'true'
43-
configuration: LS_LOG=trace
44-
install-awslocal: 'true'
45-
env:
46-
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
38+
- name: Install lstk
39+
run: |
40+
npm install -g @localstack/lstk aws-cdk
41+
lstk setup aws
4742
4843
- name: Install CDK dependencies
4944
run: cd cdk && npm ci
@@ -57,29 +52,36 @@ jobs:
5752
- name: Install Node.js Lambda dependencies
5853
run: cd demo/lambdas/nodejs && npm install --omit=dev
5954

55+
- name: Start LocalStack
56+
env:
57+
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
58+
run: |
59+
docker pull localstack/localstack-pro:latest
60+
LOCALSTACK_LS_LOG=trace lstk start
61+
6062
- name: Bootstrap CDK
6163
working-directory: cdk
6264
env:
6365
AWS_ACCESS_KEY_ID: test
6466
AWS_SECRET_ACCESS_KEY: test
6567
AWS_DEFAULT_REGION: us-east-1
66-
run: npx cdklocal bootstrap
68+
run: lstk cdk bootstrap
6769

6870
- name: Deploy CDK stack
6971
working-directory: cdk
7072
env:
7173
AWS_ACCESS_KEY_ID: test
7274
AWS_SECRET_ACCESS_KEY: test
7375
AWS_DEFAULT_REGION: us-east-1
74-
run: npx cdklocal deploy LocalstackDemoStack --require-approval never
76+
run: lstk cdk deploy LocalstackDemoStack --require-approval never
7577

7678
- name: Upload frontend to S3
7779
env:
7880
AWS_ACCESS_KEY_ID: test
7981
AWS_SECRET_ACCESS_KEY: test
8082
AWS_DEFAULT_REGION: us-east-1
8183
AWS_ENDPOINT_URL: http://localhost.localstack.cloud:4566
82-
run: awslocal s3 sync demo/web/ s3://archive-bucket/
84+
run: lstk aws s3 sync demo/web/ s3://archive-bucket/
8385

8486
- name: Run end-to-end test
8587
env:
@@ -89,7 +91,7 @@ jobs:
8991
AWS_ENDPOINT_URL: http://localhost.localstack.cloud:4566
9092
run: |
9193
echo "Discovering REST API ID..."
92-
apiId=$(awslocal apigateway get-rest-apis --output json \
94+
apiId=$(lstk aws apigateway get-rest-apis --output json \
9395
| jq -r '.items[] | select(.name=="localstack-demo") | .id')
9496
echo "API ID: $apiId"
9597
@@ -110,10 +112,10 @@ jobs:
110112
done
111113
112114
echo "Verifying S3 result file..."
113-
awslocal s3 cp "s3://archive-bucket/$reqID/result.txt" - | grep -q "Archive result" \
115+
lstk aws s3 cp "s3://archive-bucket/$reqID/result.txt" - | grep -q "Archive result" \
114116
&& echo "✅ End-to-end test passed!" \
115117
|| (echo "❌ S3 result not found" && exit 1)
116118
117119
- name: LocalStack logs (on failure)
118120
if: failure()
119-
run: localstack logs
121+
run: lstk logs

Makefile

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ check: ## Check if all required prerequisites are installed
1818
@command -v docker > /dev/null 2>&1 || { echo "Docker is not installed. Please install Docker and try again."; exit 1; }
1919
@command -v node > /dev/null 2>&1 || { echo "Node.js is not installed. Please install Node.js and try again."; exit 1; }
2020
@command -v aws > /dev/null 2>&1 || { echo "AWS CLI is not installed. Please install AWS CLI and try again."; exit 1; }
21-
@command -v awslocal > /dev/null 2>&1 || { echo "awslocal is not installed. Run: pip install awscli-local"; exit 1; }
22-
@command -v localstack > /dev/null 2>&1 || { echo "LocalStack CLI is not installed. Run: pip install localstack"; exit 1; }
21+
@command -v lstk > /dev/null 2>&1 || { echo "lstk is not installed. Run: npm install -g @localstack/lstk"; exit 1; }
22+
@command -v cdk > /dev/null 2>&1 || { echo "AWS CDK CLI is not installed. Run: npm install -g aws-cdk"; exit 1; }
2323
@command -v jq > /dev/null 2>&1 || { echo "jq is not installed. See https://jqlang.github.io/jq/download/"; exit 1; }
2424
@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; }
2525
@echo "All required prerequisites are available."
@@ -46,51 +46,47 @@ build: ## Build the CDK TypeScript app
4646
$(CDIR) && npm run build
4747

4848
bootstrap: ## Bootstrap CDK for LocalStack
49-
$(CDIR) && npm run build && npx cdklocal bootstrap
49+
$(CDIR) && npm run build && lstk cdk bootstrap
5050

5151
deploy: ## Build, deploy CDK stack to LocalStack, and upload frontend
5252
$(MAKE) bundle-ruby bundle-node
5353
$(MAKE) bootstrap
54-
$(CDIR) && npx cdklocal deploy LocalstackDemoStack --require-approval never
54+
$(CDIR) && lstk cdk deploy LocalstackDemoStack --require-approval never
5555
@echo "Uploading frontend to s3://archive-bucket/ ..."
56-
awslocal s3 sync demo/web/ s3://archive-bucket/
56+
lstk aws s3 sync demo/web/ s3://archive-bucket/
5757
@echo ""
5858
@echo "Done! Open http://localhost:4566/archive-bucket/index.html in your browser."
5959

6060
destroy: ## Destroy the deployed CDK stack on LocalStack
61-
$(CDIR) && npx cdklocal destroy LocalstackDemoStack
61+
$(CDIR) && lstk cdk destroy LocalstackDemoStack
6262

6363
send-request: ## Send a test request and poll S3 for the result
6464
@command -v jq > /dev/null 2>&1 || { echo "jq is not installed. See https://jqlang.github.io/jq/download/"; exit 1; }
6565
@echo "Looking up REST API ID..."
66-
@apiId=$$(awslocal apigateway get-rest-apis --output json | jq -r '.items[] | select(.name=="localstack-demo") | .id'); \
66+
@apiId=$$(lstk aws apigateway get-rest-apis --output json | jq -r '.items[] | select(.name=="localstack-demo") | .id'); \
6767
echo "Sending request to API ID '$$apiId' ..."; \
6868
reqID=$$(curl -s -d '{}' "http://localhost:4566/_aws/execute-api/$$apiId/local/requests" | jq -r .requestID); \
6969
echo "Received request ID '$$reqID'"; \
7070
for i in 1 2 3 4 5 6 7 8 9 10; do \
7171
echo "Polling s3://archive-bucket/ for result ..."; \
72-
awslocal s3 ls s3://archive-bucket/ | grep "$$reqID" && exit 0; \
72+
lstk aws s3 ls s3://archive-bucket/ | grep "$$reqID" && exit 0; \
7373
sleep 3; \
7474
done; \
7575
echo "Timed out waiting for result."
7676

77-
start: ## Start LocalStack in detached mode
77+
start: ## Start LocalStack
7878
@echo "Starting LocalStack..."
7979
@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; }
80-
@LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN) localstack start -d
80+
@unset AWS_ENDPOINT_URL; LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN) lstk start
8181
@echo "LocalStack started successfully."
8282

8383
stop: ## Stop LocalStack
8484
@echo "Stopping LocalStack..."
85-
@localstack stop
85+
@unset AWS_ENDPOINT_URL; lstk stop
8686
@echo "LocalStack stopped successfully."
8787

88-
ready: ## Wait until the LocalStack container is ready
89-
@echo "Waiting on the LocalStack container..."
90-
@localstack wait -t 30 && echo "LocalStack is ready to use!" || { echo "Gave up waiting on LocalStack, exiting."; exit 1; }
91-
9288
logs: ## Save LocalStack logs to logs.txt
93-
@localstack logs > logs.txt
89+
@unset AWS_ENDPOINT_URL; lstk logs > logs.txt
9490

9591
PKG_SUB_DIRS := $(dir $(shell find . -type d -name node_modules -prune -o -type d -name "vendor" -prune -o -type f -name package.json -print))
9692

@@ -100,4 +96,4 @@ update-deps: ## Update npm dependencies in all sub-projects
10096
done
10197

10298
.PHONY: usage check install bundle-ruby bundle-node build bootstrap deploy deploy-aws \
103-
destroy destroy-aws send-request start stop ready logs update-deps
99+
destroy destroy-aws send-request start stop logs update-deps

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ The following diagram shows the architecture that this sample application builds
3434

3535
## Prerequisites
3636

37-
- A valid [LocalStack for AWS license](https://localstack.cloud/pricing). Your license provides a [`LOCALSTACK_AUTH_TOKEN`](https://docs.localstack.cloud/getting-started/auth-token/) to activate LocalStack.
38-
- [`localstack` CLI](https://docs.localstack.cloud/getting-started/installation/#localstack-cli).
39-
- [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).
40-
- [CDK](https://docs.localstack.cloud/user-guide/integrations/aws-cdk/) with the [`cdklocal`](https://www.npmjs.com/package/aws-cdk-local) wrapper (installed automatically via `cdk/package.json`).
37+
- A valid [LocalStack for AWS license](https://localstack.cloud/pricing). Your license provides a [`LOCALSTACK_AUTH_TOKEN`](https://docs.localstack.cloud/aws/getting-started/auth-token/) to activate LocalStack.
38+
- [`lstk` CLI](https://docs.localstack.cloud/aws/developer-tools/running-localstack/lstk/), installed via `npm install -g @localstack/lstk` or `brew install localstack/tap/lstk`.
39+
- [AWS CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/), required by `lstk aws`.
40+
- [CDK](https://docs.localstack.cloud/user-guide/integrations/aws-cdk/) installed globally (`npm install -g aws-cdk`), used via the `lstk cdk` proxy.
4141
- [Node.js 22+](https://nodejs.org/en/download/)
4242
- [Docker](https://docs.docker.com/get-docker/) — required to bundle Ruby Lambda gems.
4343
- [`jq`](https://jqlang.github.io/jq/download/)
@@ -65,7 +65,6 @@ Set your LocalStack auth token and start LocalStack:
6565
```bash
6666
export LOCALSTACK_AUTH_TOKEN=<your-auth-token>
6767
make start
68-
make ready
6968
```
7069

7170
Deploy the full stack (bundles Lambda dependencies, bootstraps CDK, deploys, uploads frontend):
@@ -126,7 +125,7 @@ Polling s3://archive-bucket/ for result ...
126125
You can also browse the contents of the archive bucket directly:
127126

128127
```bash
129-
awslocal s3 ls s3://archive-bucket/
128+
lstk aws s3 ls s3://archive-bucket/
130129
```
131130

132131
## Summary
@@ -136,7 +135,7 @@ This sample application demonstrates how to build and test a polyglot serverless
136135
- Defining AWS infrastructure (API Gateway, Lambda, SQS, Step Functions, DynamoDB, S3) entirely with **AWS CDK in TypeScript**.
137136
- Running **three Lambda runtimes** (Node.js, Python, Ruby) side-by-side in the same CDK stack.
138137
- Serving a **React frontend from S3** that auto-discovers the API Gateway endpoint and polls for status updates.
139-
- Using `cdklocal` and `awslocal` to streamline **local deployment and testing** without touching real AWS.
138+
- Using the `lstk cdk` and `lstk aws` proxies to streamline **local deployment and testing** without touching real AWS.
140139
- Providing a **GitHub Actions workflow** that runs the full integration test suite on every push.
141140

142141
## Learn More

cdk/package-lock.json

Lines changed: 0 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cdk/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"devDependencies": {
1515
"@types/node": "^22.13.0",
1616
"aws-cdk": "^2.1111.0",
17-
"aws-cdk-local": "^2.0.0",
1817
"ts-node": "^10.9.2",
1918
"typescript": "^5.7.0"
2019
}

0 commit comments

Comments
 (0)