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
19 changes: 7 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ jobs:
with:
use-installer: true

- name: Setup SAM-Local
- name: Install lstk
run: |
pip install aws-sam-cli-local
samlocal --help
npm install -g @localstack/lstk
sam --version

- name: Install yq
run: |
Expand All @@ -60,15 +60,10 @@ jobs:
- name: Start LocalStack
env:
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
DNS_ADDRESS: 0
LOCALSTACK_DNS_ADDRESS: 0
run: |
docker pull localstack/localstack-pro:latest
# Start LocalStack in the background
LS_LOG=trace 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
echo "Startup complete"
LOCALSTACK_LS_LOG=trace lstk start

- name: Deploy the application
run: |
Expand All @@ -77,12 +72,12 @@ jobs:
- name: Check deployed resources
run: |
sleep 20
samlocal list stack-outputs --stack-name sam-app --region us-east-1 --output json
lstk sam list stack-outputs --stack-name sam-app --region us-east-1 --output json

- name: Run integration tests
run: |
set -euo pipefail
api_id=$(samlocal list stack-outputs --stack-name sam-app --region us-east-1 --output json \
api_id=$(lstk sam list stack-outputs --stack-name sam-app --region us-east-1 --output json \
| jq -r '.[] | select(.OutputKey=="ApiBasePath") | .OutputValue' \
| sed -E 's#https?://##; s#\..*##')
base="https://${api_id}.execute-api.localhost.localstack.cloud:4566"
Expand Down
16 changes: 5 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ usage:

## Install dependencies
install:
@which localstack || pip install localstack
@which samlocal || pip install aws-sam-cli-local
@which lstk || npm install -g @localstack/lstk
@which artillery || npm install -g artillery@latest
pip install -r requirements.txt

Expand All @@ -21,20 +20,15 @@ deploy:
## 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

## 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 deploy start stop ready logs
.PHONY: usage install deploy start stop logs
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ We are using the following AWS services to build our infrastructure:

## 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).
* [Serverless Application Model](https://docs.localstack.cloud/user-guide/integrations/aws-sam/) with the [samlocal](https://github.com/localstack/aws-sam-cli-local) installed.
* 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`.
* [Serverless Application Model](https://docs.localstack.cloud/user-guide/integrations/aws-sam/), used via the `lstk sam` proxy.
* [Python 3.9 installed](https://www.python.org/downloads/).
* [Node.js](https://nodejs.org/en/download) with npm package manager.
* [Artillery](https://artillery.io/docs/guides/overview/welcome.html) to generate some load towards both the apis.
Expand All @@ -47,7 +47,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 @@ -63,16 +62,16 @@ Alternatively, here are instructions to deploy it manually step-by-step.
This stack facilitates the seamless provisioning of an RDS Aurora PostgreSQL database, accompanied by an RDS Proxy to serve as its front-end. The entire setup will be securely deployed within a VPC, utilizing three private subnets. The essential parameters required for the [next step](#deploy-serverless-workload-using-rds-aurora-as-backend) are also provided as stack outputs, ensuring a smooth continuation of the deployment process.

```bash
samlocal build -t rds-with-proxy.yaml --use-container
samlocal deploy -t rds-with-proxy.yaml --guided
lstk sam build -t rds-with-proxy.yaml --use-container
lstk sam deploy -t rds-with-proxy.yaml --guided
```
### Deploy serverless workload using RDS Aurora as backend

To initiate the initial build and deployment of your application, execute the following command in your shell:

```bash
samlocal build --use-container
samlocal deploy --guided
lstk sam build --use-container
lstk sam deploy --guided
```

### Create a user with `rds_iam` role
Expand Down
10 changes: 5 additions & 5 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
samlocal deploy -t rds-with-proxy.yaml\
lstk sam deploy -t rds-with-proxy.yaml\
--stack-name sam-infra \
--region us-east-1 \
--capabilities CAPABILITY_IAM \
--no-fail-on-empty-changeset \
--no-confirm-changeset

samlocal list stack-outputs \
lstk sam list stack-outputs \
--stack-name sam-infra \
--region us-east-1 \
--output json > output-infra.json
Expand All @@ -19,8 +19,8 @@ database_port=$(jq -r '.[] | select(.OutputKey=="databasePort") | .OutputValue'
secret_arn=$(jq -r '.[] | select(.OutputKey=="secretArn") | .OutputValue' output-infra.json)
lambda_sg_group_id=$(jq -r '.[] | select(.OutputKey=="lambdaSgGroupId") | .OutputValue' output-infra.json)

samlocal build --use-container
samlocal deploy \
lstk sam build --use-container
lstk sam deploy \
--stack-name sam-app \
--region us-east-1 \
--capabilities CAPABILITY_IAM \
Expand All @@ -38,7 +38,7 @@ samlocal deploy \
CreateFunctionSecurityGroup=True \
LambdaSecurityGroupId=$lambda_sg_group_id

samlocal list stack-outputs \
lstk sam list stack-outputs \
--stack-name sam-app \
--region us-east-1 \
--output json > output-app.json
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
psycopg2-binary
psycopg2-binary
boto3
Loading