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
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ jobs:
run: |
docker pull localstack/localstack-pro:latest
# Start LocalStack in the background
DEBUG=1 LOCALSTACK_AUTH_TOKEN=$LOCALSTACK_AUTH_TOKEN localstack start -d
# Wait 30 seconds for the LocalStack container to become ready before timing out
echo "Waiting for LocalStack startup..."
localstack wait -t 15
LOCALSTACK_DEBUG=1 LOCALSTACK_AUTH_TOKEN=$LOCALSTACK_AUTH_TOKEN lstk start --non-interactive
echo "Startup complete"

- name: Set up the AWS profile for lstk aws
run: lstk setup aws

- name: Run the application
run: |
awslocal s3 mb s3://testbucket
lstk aws s3 mb s3://testbucket
make run

- name: Send a Slack notification
Expand Down
11 changes: 5 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,25 @@ usage: ## Show this help

install: ## Install dependencies
@test -e node_modules || yarn install
@which localstack || pip install localstack
@which awslocal || pip install awscli-local
@which lstk || npm install -g @localstack/lstk
@test -e .venv || (python3 -m venv .venv; source .venv/bin/activate; pip install -r requirements.txt)

run: ## Deploy the app locally and run an AppSync GraphQL test invocation
./run.sh

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

stop:
@echo
localstack stop
lstk stop
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)

logs:
@localstack logs > logs.txt
@lstk logs > logs.txt

test-ci:
make start install ready run; return_code=`echo $$?`;\
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ We are using the following AWS services and third-party integrations to build ou

## 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` 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/).
- [AWS CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/) (required by `lstk aws`).
- [Python](https://www.python.org/downloads/)
- [`cURL`](https://curl.se/)
- [`wscat`](https://github.com/websockets/wscat)
Expand Down Expand Up @@ -70,8 +70,8 @@ After a few seconds, the infrastructure should be deployed successfully. Fetch t

```sh
export APPSYNC_URL=http://localhost:4566/graphql
api_id=$(awslocal appsync list-graphql-apis | jq -r '(.graphqlApis[] | select(.name=="test-api")).apiId')
api_key=$(awslocal appsync create-api-key --api-id $api_id | jq -r .apiKey.id)
api_id=$(lstk aws appsync list-graphql-apis | jq -r '(.graphqlApis[] | select(.name=="test-api")).apiId')
api_key=$(lstk aws appsync create-api-key --api-id $api_id | jq -r .apiKey.id)
echo $api_key
echo $api_id
```
Expand Down Expand Up @@ -111,7 +111,7 @@ curl -H "Content-Type: application/json" -H "x-api-key: $api_key" -d '{"query":"
We can now perform a scan operation on the DynamoDB table which will include an entry with `id123` as the `id`:

```sh
awslocal dynamodb scan --table-name table1
lstk aws dynamodb scan --table-name table1
{
"Items": [
{
Expand Down
8 changes: 4 additions & 4 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ set -e
APPSYNC_URL=http://localhost:4566/graphql

# Create a new S3 bucket
awslocal s3 mb s3://testbucket
lstk aws s3 mb s3://testbucket

# Deploy the Serverless app to the local environment and run the tests
echo "Deploying Serverless app to local environment"; \
SLS_DEBUG=1 yarn deploy && \
echo "Serverless app successfully deployed." && \
api_id=$(awslocal appsync list-graphql-apis | jq -r '(.graphqlApis[] | select(.name=="test-api")).apiId') && \
api_id=$(lstk aws appsync list-graphql-apis | jq -r '(.graphqlApis[] | select(.name=="test-api")).apiId') && \
echo "DEBUG: api_id is: $api_id" && \
api_key=$(awslocal appsync create-api-key --api-id $api_id | jq -r .apiKey.id) && \
api_key=$(lstk aws appsync create-api-key --api-id $api_id | jq -r .apiKey.id) && \
echo "DEBUG: api_key is: $api_key" && \
echo "Starting a WebSocket client to subscribe to GraphQL mutation operations." && \
source .venv/bin/activate && \
Expand All @@ -22,7 +22,7 @@ echo "Now trying to invoke the AppSync API for DynamoDB integration under $APPSY
curl -H "Content-Type: application/json" -H "x-api-key: $api_key" -d '{"query":"mutation {addPostDDB(id: \"id123\"){id}}"}' $APPSYNC_URL/$api_id && \
curl -H "Content-Type: application/json" -H "x-api-key: $api_key" -d '{"query":"query {getPostsDDB{id}}"}' $APPSYNC_URL/$api_id && \
echo "Scanning items from DynamoDB table - should include entry with 'id123':" && \
result_ddb_scan=$(awslocal dynamodb scan --table-name table1) && \
result_ddb_scan=$(lstk aws dynamodb scan --table-name table1) && \
echo $result_ddb_scan | jq -r . && \
echo "Now trying to invoke the AppSync API for RDS integration." && \
curl -H "Content-Type: application/json" -H "x-api-key: $api_key" -d '{"query":"mutation {addPostRDS(id: \"id123\"){id}}"}' $APPSYNC_URL/$api_id && \
Expand Down
1 change: 1 addition & 0 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ resources:
DBClusterIdentifier: ${self:custom.rds.dbcluster}
MasterUsername: ${self:custom.rds.username}
MasterUserPassword: ${self:custom.rds.password}
EnableHttpEndpoint: true
RDSDatabaseSecret:
Type: AWS::SecretsManager::Secret
Properties:
Expand Down
Loading