From ba266251654c0e4f6c1f3fab6ab14b0a9f534431 Mon Sep 17 00:00:00 2001 From: Harsh Mishra Date: Fri, 4 Sep 2026 16:35:02 +0530 Subject: [PATCH 1/2] Migrate from the localstack CLI to lstk --- .github/workflows/main.yml | 9 ++++----- Makefile | 21 +++++++-------------- README.md | 29 ++++++++++++++--------------- package.json | 3 +-- run-integ-tests.sh | 4 ++-- 5 files changed, 28 insertions(+), 38 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f9be7bf..e9ad4e2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,6 +27,9 @@ jobs: with: node-version: 22 + - name: Install lstk + run: npm install -g @localstack/lstk + - name: Install dependencies run: | npm install @@ -35,12 +38,8 @@ jobs: env: LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }} run: | - pip install localstack awscli-local[ver1] docker pull localstack/localstack-pro:latest - EXTRA_CORS_ALLOWED_ORIGINS=* DEBUG=1 LOCALSTACK_AUTH_TOKEN=$LOCALSTACK_AUTH_TOKEN localstack start -d - echo "Waiting for LocalStack startup..." - localstack wait -t 30 - echo "Startup complete" + LOCALSTACK_EXTRA_CORS_ALLOWED_ORIGINS=* LOCALSTACK_DEBUG=1 lstk start - name: Run integration tests run: | diff --git a/Makefile b/Makefile index 014161d..a142dcd 100644 --- a/Makefile +++ b/Makefile @@ -9,32 +9,25 @@ usage: ## Install dependencies install: - @which localstack || pip install localstack - @which awslocal || pip install awscli-local - @which cdklocal || npm install -g aws-cdk-local aws-cdk + @which lstk || npm install -g @localstack/lstk aws-cdk deploy: test -e node_modules || yarn; \ - cdklocal bootstrap aws://000000000000/$$AWS_DEFAULT_REGION; \ - cdklocal deploy --outputs-file cdk_outputs.json + lstk cdk bootstrap aws://000000000000/$$AWS_DEFAULT_REGION; \ + lstk cdk deploy --outputs-file cdk_outputs.json ## Start LocalStack in detached mode start: @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) - @LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN) EXTRA_CORS_ALLOWED_ORIGINS=* localstack start -d + @LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN) LOCALSTACK_EXTRA_CORS_ALLOWED_ORIGINS=* lstk start ## Stop the Running LocalStack container stop: @echo - localstack stop - -## Make sure the LocalStack container is up -ready: - @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) + lstk stop ## Save the logs in a separate file, since the LS container will only contain the logs of the last sample run. logs: - @localstack logs > logs.txt + @lstk logs > logs.txt -.PHONY: usage install run start stop ready logs +.PHONY: usage install run start stop logs diff --git a/README.md b/README.md index 044c9a8..3ed2937 100644 --- a/README.md +++ b/README.md @@ -26,10 +26,10 @@ We are using the following AWS services and their features to build our infrastr ## Prerequisites -- 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. -- [`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`](https://github.com/localstack/awscli-local) wrapper. -- [CDK](https://docs.localstack.cloud/user-guide/integrations/aws-cdk/) with the [`cdklocal`](https://github.com/localstack/aws-cdk-local) wrapper. +- 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. +- [`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`. +- [AWS CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/), required by `lstk aws`. +- [CDK](https://docs.localstack.cloud/user-guide/integrations/aws-cdk/), used via the `lstk cdk` proxy. - [Node.js](https://nodejs.org/en/download/) with `npm` package manager. ## Start LocalStack @@ -39,7 +39,6 @@ Start LocalStack with the `LOCALSTACK_AUTH_TOKEN` pre-configured: ```shell export LOCALSTACK_AUTH_TOKEN= make start -make ready ``` ## Instructions @@ -48,7 +47,7 @@ You can build and deploy the sample application on LocalStack by running our `Ma ### Creating the infrastructure -To create the AWS infrastructure locally, you can use CDK and our `cdklocal` wrapper. Before you can deploy the infrastructure, you need to install the application dependencies: +To create the AWS infrastructure locally, you can use CDK and the `lstk cdk` proxy. Before you can deploy the infrastructure, you need to install the application dependencies: ```shell yarn @@ -57,8 +56,8 @@ yarn To deploy the infrastructure, you can run the following command: ```shell -cdklocal bootstrap aws://000000000000/us-east-1 -cdklocal deploy +lstk cdk bootstrap aws://000000000000/us-east-1 +lstk cdk deploy ``` *Note: Make sure your region is set to `us-east-1` in your AWS CLI configuration. Alternatively you can adjust the bootstrap command to match your region. @@ -71,22 +70,22 @@ As an output of the last command, you will see the API Gateway endpoint URL. You To test the microservice, we will send Friend Action Events to the front SQS queue. We will use the AWS CLI to send the events to the queue. To get the Queue URL, you can run the following command: ```shell -awslocal sqs list-queues +lstk aws sqs list-queues ``` Get the URL of the Front Queue and use the following commands to send a friend request event: ```shell -awslocal sqs send-message-batch --queue-url --entries file://test/testMessagesFirst.json -awslocal sqs send-message-batch --queue-url --entries file://test/testMessagesSecond.json -awslocal sqs send-message-batch --queue-url --entries file://test/testMessagesThird.json +lstk aws sqs send-message-batch --queue-url --entries file://test/testMessagesFirst.json +lstk aws sqs send-message-batch --queue-url --entries file://test/testMessagesSecond.json +lstk aws sqs send-message-batch --queue-url --entries file://test/testMessagesThird.json ``` To test corner cases, you can send the following messages to the queue: ```shell -awslocal sqs send-message-batch --queue-url --entries file://test/cornerCase1.json -awslocal sqs send-message-batch --queue-url --entries file://test/cornerCase2.json +lstk aws sqs send-message-batch --queue-url --entries file://test/cornerCase1.json +lstk aws sqs send-message-batch --queue-url --entries file://test/cornerCase2.json ``` To test the microservice now, send the following command using `cURL`: @@ -105,7 +104,7 @@ yarn test ## GitHub Action -This application sample hosts an example GitHub Action workflow that starts up LocalStack, deploys the infrastructure, and checks the created resources using `awslocal`. You can find the workflow in the `.github/workflows/main.yml` file. To run the workflow, you can fork this repository and push a commit to the `main` branch. +This application sample hosts an example GitHub Action workflow that starts up LocalStack, deploys the infrastructure, and checks the created resources using `lstk aws`. You can find the workflow in the `.github/workflows/main.yml` file. To run the workflow, you can fork this repository and push a commit to the `main` branch. Users can adapt this example workflow to run in their own CI environment. LocalStack supports various CI environments, including GitHub Actions, CircleCI, Jenkins, Travis CI, and more. You can find more information about the CI integration in the [LocalStack documentation](https://docs.localstack.cloud/user-guide/ci/). diff --git a/package.json b/package.json index ef6c36d..2e19540 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "build": "tsc", "watch": "tsc -w", "cdk": "cdk", - "cdklocal": "cdklocal", + "cdklocal": "lstk cdk", "integ-test": "./run-integ-tests.sh" }, "devDependencies": { @@ -17,7 +17,6 @@ "@types/aws-lambda": "^8.10.145", "@types/node": "^22.0.0", "aws-cdk": "latest", - "aws-cdk-local": "^3.0.0", "ts-node": "^10.9.2", "typescript": "~5.5.0" }, diff --git a/run-integ-tests.sh b/run-integ-tests.sh index 5c0bccf..58ea837 100755 --- a/run-integ-tests.sh +++ b/run-integ-tests.sh @@ -27,7 +27,7 @@ export NODE_TLS_REJECT_UNAUTHORIZED="0" echo "==> Checking LocalStack is running..." if ! curl -s "http://localhost:4566/_localstack/health" > /dev/null 2>&1; then echo "ERROR: LocalStack is not running." - echo "Start it with: localstack start -d" + echo "Start it with: lstk start" exit 1 fi echo " LocalStack is running." @@ -38,7 +38,7 @@ npx tsc # Bootstrap CDK on LocalStack echo "==> Bootstrapping CDK on LocalStack..." -npx cdklocal bootstrap aws://000000000000/us-east-1 --force 2>&1 || true +lstk cdk bootstrap aws://000000000000/us-east-1 --force 2>&1 || true # Run integ-runner echo "" From b66959393891ab7d83fd194f5325144e17958ea6 Mon Sep 17 00:00:00 2001 From: Harsh Mishra Date: Fri, 4 Sep 2026 16:43:04 +0530 Subject: [PATCH 2/2] Install the CDK CLI in CI; lstk cdk requires cdk on PATH --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e9ad4e2..2a66a61 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,8 +27,8 @@ jobs: with: node-version: 22 - - name: Install lstk - run: npm install -g @localstack/lstk + - name: Install lstk and CDK + run: npm install -g @localstack/lstk aws-cdk - name: Install dependencies run: |