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
25 changes: 12 additions & 13 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jobs:

- name: Install CDK
run: |
npm install -g aws-cdk-local aws-cdk
cdklocal --version
npm install -g @localstack/lstk aws-cdk
cdk --version

- name: Install dependencies
run: |
Expand All @@ -39,16 +39,14 @@ jobs:
- name: Start LocalStack
env:
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
DNS_ADDRESS: 0
LOCALSTACK_DNS_ADDRESS: 0
run: |
pip install localstack awscli-local[ver1]
pip install terraform-local
docker pull localstack/localstack:latest
# Start LocalStack in the background
LS_LOG=trace localstack start -d
LOCALSTACK_LS_LOG=trace lstk start --non-interactive
# Wait 30 seconds for the LocalStack container to become ready before timing out
echo "Waiting for LocalStack startup..."
localstack wait -t 15
lstk status
echo "Startup complete"

- name: Deploy using CDK
Expand All @@ -58,15 +56,16 @@ jobs:
AWS_ACCESS_KEY_ID: test
AWS_SECRET_ACCESS_KEY: test
run: |
cdklocal bootstrap aws://000000000000/us-east-1
cdklocal deploy --all --require-approval never
lstk cdk bootstrap aws://000000000000/us-east-1
lstk cdk deploy --all --require-approval never

- name: List the resources
run: |
awslocal lambda list-functions
awslocal sqs list-queues
awslocal dynamodb list-tables
awslocal stepfunctions list-state-machines
lstk setup aws --non-interactive --force
lstk aws lambda list-functions
lstk aws sqs list-queues
lstk aws dynamodb list-tables
lstk aws stepfunctions list-state-machines

- name: Send a Slack notification
if: failure() || github.event_name != 'pull_request'
Expand Down
15 changes: 6 additions & 9 deletions .github/workflows/pods.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,18 @@ jobs:
with:
python-version: '3.10'

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

- name: Start LocalStack
uses: LocalStack/setup-localstack@main
with:
image-tag: 'latest'
use-pro: 'true'
env:
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
run: lstk start --non-interactive

- name: Load the Cloud Pod
uses: LocalStack/setup-localstack/cloud-pods@main
with:
name: loan-broker-infra
action: load
- name: Load the Cloud Pod
env:
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
run: lstk snapshot load pod:loan-broker-infra

- name: Run integration tests
run: |
Expand Down
16 changes: 7 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,30 @@ 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

deploy:
test -e node_modules || yarn; \
cdklocal bootstrap aws://000000000000/us-east-1; \
cdklocal deploy --all --require-approval never
lstk cdk bootstrap aws://000000000000/us-east-1; \
lstk cdk deploy --all --require-approval never

## 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) localstack start -d
@LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN) lstk start --non-interactive

## Stop the Running LocalStack container
stop:
@echo
localstack stop
lstk 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 status && echo LocalStack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1)

## 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
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ The following diagram shows the architecture that this sample application builds

## 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).
- [Cloud Development Kit](https://docs.localstack.cloud/user-guide/integrations/aws-cdk/) with the [`cdklocal`](https://www.npmjs.com/package/aws-cdk-local) installed.
- [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).
- 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/).
- [Cloud Development Kit](https://docs.localstack.cloud/user-guide/integrations/aws-cdk/).
- [AWS CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/), required by `lstk aws`.
- [Node.js](https://nodejs.org/en/download), and [`yarn`](https://yarnpkg.com/).

## Start LocalStack
Expand All @@ -50,15 +50,15 @@ make start
make ready
```

We specified DEBUG=1 to get the printed LocalStack logs directly in the terminal to help us see the event-driven architecture in action. If you prefer running LocalStack in detached mode, you can add the `-d` flag to the `localstack start` command, and use Docker Desktop to view the logs.
We specified DEBUG=1 to get the printed LocalStack logs directly in the terminal to help us see the event-driven architecture in action. If you prefer running LocalStack in detached mode, you can add the `--non-interactive` flag to the `lstk start` command, and use Docker Desktop to view the logs.

## Instructions

You can build and deploy the sample application on LocalStack by running our `Makefile` commands. To deploy the infrastructure, you can run `make deploy` after installing the application dependencies, and run the test steps manually. Here are instructions to deploy and test it manually step-by-step.

### Deploying the application

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 with `lstk cdk`. Before you can deploy the infrastructure, you need to install the application dependencies:

```sh
yarn
Expand All @@ -67,8 +67,8 @@ yarn
To deploy the infrastructure, you can run the following command:

```sh
cdklocal bootstrap
cdklocal deploy --all
lstk cdk bootstrap
lstk cdk deploy --all
```

This will deploy the `LoanBroker-RecipientList-Stack` and `LoanBroker-PubSub-Stack` stacks. You will see the following output:
Expand All @@ -87,15 +87,15 @@ Take a note of the `LoanBroker-RecipientList-Stack.LoanBrokerArn` output. You wi
Before you can test the application, you need to pre-populate the `LoanBrokerBanksTable` for the `RecipientsList` stack:

```sh
awslocal dynamodb put-item \
lstk aws dynamodb put-item \
--table-name=LoanBrokerBanksTable \
--item='{ "Type": { "S": "Home" }, "BankAddress": {"L": [ { "S": "BankRecipientPremium" }, { "S": "BankRecipientUniversal" }, { "S": "BankRecipientPawnshop" } ] } }'
```

We can start the State Machine execution to get quotes from the banks after submitting a loan application. Run the following command:

```sh
awslocal stepfunctions start-execution \
lstk aws stepfunctions start-execution \
--name=cli-test-run \
--state-machine-arn=<STATE_MACHINE_ARN> \
--input="{\"SSN\": \"123-45-6789\", \"Amount\": 500000, \"Term\": 30 }"
Expand All @@ -113,7 +113,7 @@ Replace `<STATE_MACHINE_ARN>` with the `LoanBroker-RecipientList-Stack.LoanBroke
You can use the Execution ARN to see the output of the State Machine execution:

```sh
awslocal stepfunctions describe-execution \
lstk aws stepfunctions describe-execution \
--execution-arn=<EXECUTION_ARN> \
--query="output" | jq -r '. | fromjson'
```
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@aws-sdk/util-dynamodb": "^3.301.0",
"@types/jest": "^26.0.10",
"@types/node": "10.17.27",
"aws-cdk": "2.70.0",
"aws-cdk": "2.1133.0",
"jest": "^26.4.2",
"ts-jest": "^26.2.0",
"ts-node": "^9.0.0",
Expand Down
12 changes: 5 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1583,12 +1583,10 @@ aws-cdk-lib@2.70.0:
semver "^7.3.8"
yaml "1.10.2"

aws-cdk@2.70.0:
version "2.70.0"
resolved "https://registry.yarnpkg.com/aws-cdk/-/aws-cdk-2.70.0.tgz#95377f7ddc8f5a0a625f5feb15e610b32b70e3cf"
integrity sha512-B12e+h8FNNS2BGgBKzKrU541shC/9CWeC1Z/CwX2NKxPgbeP2eGtgR1hCfT/VaotcfJ8+dSd4I32nNNc+wz+QA==
optionalDependencies:
fsevents "2.3.2"
aws-cdk@2.1133.0:
version "2.1133.0"
resolved "https://registry.yarnpkg.com/aws-cdk/-/aws-cdk-2.1133.0.tgz#ff1028d329939da96edeb6bfb8b1f0b975ddf378"
integrity sha512-DGlCBwqxSHTe1u/IoT5WV+Bbd2K3UhwFHsdMqb2nQa1fkJmaQgoNFu0It+p3HxyMWeW+gKsVzT5KcjQPQ6Kzuw==

babel-jest@^26.6.3:
version "26.6.3"
Expand Down Expand Up @@ -2298,7 +2296,7 @@ fs.realpath@^1.0.0:
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==

fsevents@2.3.2, fsevents@^2.1.2:
fsevents@^2.1.2:
version "2.3.2"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a"
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==
Expand Down
Loading