Skip to content
Merged
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
9 changes: 4 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ jobs:
with:
node-version: 22

- name: Install lstk and CDK
run: npm install -g @localstack/lstk aws-cdk

- name: Install dependencies
run: |
npm install
Expand All @@ -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: |
Expand Down
21 changes: 7 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 14 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,7 +39,6 @@ Start LocalStack with the `LOCALSTACK_AUTH_TOKEN` pre-configured:
```shell
export LOCALSTACK_AUTH_TOKEN=<your-auth-token>
make start
make ready
```

## Instructions
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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 <QUEUE_URL> --entries file://test/testMessagesFirst.json
awslocal sqs send-message-batch --queue-url <QUEUE_URL> --entries file://test/testMessagesSecond.json
awslocal sqs send-message-batch --queue-url <QUEUE_URL> --entries file://test/testMessagesThird.json
lstk aws sqs send-message-batch --queue-url <QUEUE_URL> --entries file://test/testMessagesFirst.json
lstk aws sqs send-message-batch --queue-url <QUEUE_URL> --entries file://test/testMessagesSecond.json
lstk aws sqs send-message-batch --queue-url <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 <QUEUE_URL> --entries file://test/cornerCase1.json
awslocal sqs send-message-batch --queue-url <QUEUE_URL> --entries file://test/cornerCase2.json
lstk aws sqs send-message-batch --queue-url <QUEUE_URL> --entries file://test/cornerCase1.json
lstk aws sqs send-message-batch --queue-url <QUEUE_URL> --entries file://test/cornerCase2.json
```

To test the microservice now, send the following command using `cURL`:
Expand All @@ -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/).

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build": "tsc",
"watch": "tsc -w",
"cdk": "cdk",
"cdklocal": "cdklocal",
"cdklocal": "lstk cdk",
"integ-test": "./run-integ-tests.sh"
},
"devDependencies": {
Expand All @@ -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"
},
Expand Down
4 changes: 2 additions & 2 deletions run-integ-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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 ""
Expand Down
Loading