Skip to content

Commit 9122524

Browse files
steffyPtinyg210HarshCasper
authored
configure sample to work with LocalStack (#1)
* run sample against LocalStack + add query-lambda function for testing * polish readme, add license note, add Makefile * add sample workflow * README updates * add diagram for the application architecture * replace diagram with a better centered one * fix nits * Update README.md Co-authored-by: steffyP <steffyP@users.noreply.github.com> * Update README.md Co-authored-by: steffyP <steffyP@users.noreply.github.com> --------- Co-authored-by: AncaGhenade <ancaghenade@gmail.com> Co-authored-by: HarshCasper <erbeusgriffincasper@gmail.com>
1 parent 2396266 commit 9122524

File tree

11 files changed

+467
-193
lines changed

11 files changed

+467
-193
lines changed

.github/workflows/main.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Deploy on LocalStack
2+
3+
on:
4+
push:
5+
paths-ignore:
6+
- 'README.md'
7+
branches:
8+
- main
9+
pull_request:
10+
branches:
11+
- main
12+
13+
jobs:
14+
smoke-test:
15+
name: Setup infrastructure
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v3
20+
21+
- name: Setup Python
22+
uses: actions/setup-python@v4
23+
with:
24+
python-version: '3.9'
25+
26+
- name: Setup Nodejs
27+
uses: actions/setup-node@v3
28+
with:
29+
node-version: 16
30+
31+
- name: Install dependencies
32+
run: |
33+
make install
34+
35+
- name: Start LocalStack
36+
env:
37+
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
38+
LOCALSTACK_VOLUME_DIR: ${{ github.workspace }}/ls_test
39+
run: |
40+
mkdir ls_test
41+
docker pull localstack/localstack-pro:latest
42+
# Start LocalStack in the background
43+
DEBUG=1 RDS_MYSQL_DOCKER=1 localstack start -d
44+
# Wait 30 seconds for the LocalStack container to become ready before timing out
45+
echo "Waiting for LocalStack startup..."
46+
localstack wait -t 15
47+
echo "Startup complete"
48+
49+
- name: Deploy the application
50+
env:
51+
AWS_ACCESS_KEY_ID: test
52+
AWS_SECRET_ACCESS_KEY: test
53+
AWS_DEFAULT_REGION: us-east-1
54+
run: |
55+
make build
56+
make bootstrap
57+
make deploy
58+
59+
- name: Show Logs
60+
if: failure()
61+
run: |
62+
localstack logs
63+
64+
- name: Smoke Test
65+
run: |
66+
awslocal --version
67+
awslocal lambda invoke --cli-binary-format raw-in-base64-out --function-name my-lambda-rds-query-helper --payload '{"sqlQuery": "show tables", "secretName":"/rdsinitexample/rds/creds/mysql-01"}' output
68+
echo "show tables:"
69+
cat output
70+
awslocal lambda invoke --cli-binary-format raw-in-base64-out --function-name my-lambda-rds-query-helper --payload '{"sqlQuery": "select Author from Books", "secretName":"/rdsinitexample/rds/creds/mysql-01"}' output
71+
echo "select Author from Books:"
72+
cat output
73+
return_status=$(cat output | jq -r .status)
74+
if [ "SUCCESS" != ${return_status} ]; then
75+
echo "unexpected response: ${return_status}"
76+
cat output
77+
exit 1
78+
fi
79+
- name: Show Logs
80+
if: failure()
81+
run: |
82+
localstack logs

LICENSE

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,18 @@ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
1313
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1414
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1515

16+
17+
Copyright 2023 LocalStack. All Rights Reserved.
18+
19+
Permission is hereby granted, free of charge, to any person obtaining a copy of
20+
this software and associated documentation files (the "Software"), to deal in
21+
the Software without restriction, including without limitation the rights to
22+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
23+
the Software, and to permit persons to whom the Software is furnished to do so.
24+
25+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
27+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
28+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
29+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Makefile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
export AWS_ACCESS_KEY_ID ?= test
2+
export AWS_SECRET_ACCESS_KEY ?= test
3+
export AWS_DEFAULT_REGION=us-east-1
4+
SHELL := /bin/bash
5+
6+
## Show this help
7+
usage:
8+
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
9+
10+
## Install dependencies
11+
install:
12+
@which localstack || pip install localstack
13+
@which awslocal || pip install awscli-local
14+
@which cdklocal || npm install -g aws-cdk-local aws-cdk
15+
16+
## Deploy the infrastructure
17+
build:
18+
npm install && cd demos/rds-query-fn-code && npm install
19+
20+
## Bootstap the CDK sample
21+
bootstrap:
22+
cdklocal bootstrap
23+
24+
## Deploy the CDK sample
25+
deploy:
26+
cdklocal deploy --require-approval never
27+
28+
## Start LocalStack in detached mode
29+
start:
30+
RDS_MYSQL_DOCKER=1 localstack start -d
31+
32+
## Stop the Running LocalStack container
33+
stop:
34+
@echo
35+
localstack stop
36+
37+
## Make sure the LocalStack container is up
38+
ready:
39+
@echo Waiting on the LocalStack container...
40+
@localstack wait -t 30 && echo LocalStack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1)
41+
42+
## Save the logs in a separate file, since the LS container will only contain the logs of the last sample run.
43+
logs:
44+
@localstack logs > logs.txt
45+
46+
.PHONY: usage install bootstrap build deploy deploy start stop ready logs

0 commit comments

Comments
 (0)