Skip to content

Commit

Permalink
configure sample to work with LocalStack (#16)
Browse files Browse the repository at this point in the history
* changes to make the sample run against LS

* modify proxy yaml files for load testing

* change the database used from mysql to postgres

* remove connection print statement

* create iam user for postgres

* add makefile

* add the deployment script

* install artillery package

* update README

* update README with PostgreSQL

* update readme file with yq and jg

* add contributing section

* update the architecture image

* add github actions

* update job name

* update actions with jq and yq

* uncomment start localstack gh action

* uncomment start localstack gh action (#4)

* update jq and yq in gh actions

* Update jq and yq setup in gh actions (#5)

* install requirements.txt dependencies

* add requirements.txt file

* update gitignore

* update README

* add services being used in README

* add github actions to readme

* Remove print statements from app file

* Remove extra space from create-user script

* remove print statements from rds app file

* add static db name

* Update CONTRIBUTING.md

* update LICENSE and README

* update README

* update License

* improve the README

---------

Co-authored-by: Anca G <[email protected]>
Co-authored-by: HarshCasper <[email protected]>
  • Loading branch information
3 people authored Jul 25, 2023
1 parent 2686ff5 commit af50aaf
Show file tree
Hide file tree
Showing 19 changed files with 397 additions and 132 deletions.
105 changes: 105 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: Create Infra on LocalStack

on:
push:
paths-ignore:
- 'README.md'
branches:
- main
pull_request:
branches:
- main
schedule:
# “At 00:00 on Sunday.”
- cron: "0 0 * * 0"
workflow_dispatch:

jobs:
serverless:
name: Setup infrastructure using Serverless Framework
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Setup Nodejs
uses: actions/setup-node@v3
with:
node-version: 16

- name: Setup SAM
uses: aws-actions/setup-sam@v2
with:
use-installer: true

- name: Setup SAM-Local
run: |
pip install aws-sam-cli-local
samlocal --help
- name: Install yq
run: |
sudo add-apt-repository ppa:rmescandon/yq
sudo apt update
sudo apt install yq -y
- name: Install jq
run: |
sudo apt-get update
sudo apt-get install jq -y
- name: Install dependencies
run: |
make install
- name: Start LocalStack
env:
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
DNS_ADDRESS: 0
run: |
docker pull localstack/localstack-pro:latest
# Start LocalStack in the background
LS_LOG=trace 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"
- name: Deploy the application
run: |
make deploy
- name: Check deployed resources
run: |
sleep 20
samlocal list stack-outputs --stack-name sam-app --region us-east-1 --output json
- name: Send a Slack notification
if: failure() || github.event_name != 'pull_request'
uses: ravsamhq/notify-slack-action@v2
with:
status: ${{ job.status }}
token: ${{ secrets.GITHUB_TOKEN }}
notification_title: "{workflow} has {status_message}"
message_format: "{emoji} *{workflow}* {status_message} in <{repo_url}|{repo}>"
footer: "Linked Repo <{repo_url}|{repo}> | <{run_url}|View Workflow run>"
notify_when: "failure"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

- name: Generate a Diagnostic Report
if: failure()
run: |
curl -s localhost:4566/_localstack/diagnose | gzip -cf > diagnose.json.gz
- name: Upload the Diagnostic Report
if: failure()
uses: actions/upload-artifact@v3
with:
name: diagnose.json.gz
path: ./diagnose.json.gz
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,5 @@ $RECYCLE.BIN/
/.idea/
/samconfig.toml
/samconfig-rds.toml
/output-app.json
/output-infra.json
20 changes: 7 additions & 13 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ information to effectively respond to your bug report or contribution.

We welcome you to use the GitHub issue tracker to report bugs or suggest features.

When filing an issue, please check existing open, or recently closed, issues to make sure somebody else hasn't already
When filing an issue, please check existing open or recently closed issues to make sure somebody else hasn't already
reported the issue. Please try to include as much information as you can. Details like these are incredibly useful:

* A reproducible test case or series of steps
Expand All @@ -21,11 +21,11 @@ reported the issue. Please try to include as much information as you can. Detail


## Contributing via Pull Requests
Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that:
Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure the following:

1. You are working against the latest source on the *main* branch.
2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already.
3. You open an issue to discuss any significant work - we would hate for your time to be wasted.
2. You check existing open and recently merged pull requests to make sure someone else hasn't addressed the problem already.
3. You open an issue to discuss any significant work - we would hate to waste your time.

To send us a pull request, please:

Expand All @@ -36,7 +36,7 @@ To send us a pull request, please:
5. Send us a pull request, answering any default questions in the pull request interface.
6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation.

GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and
GitHub provides additional documents on [forking a repository](https://help.github.com/articles/fork-a-repo/) and
[creating a pull request](https://help.github.com/articles/creating-a-pull-request/).


Expand All @@ -45,15 +45,9 @@ Looking at the existing issues is a great way to find something to contribute on


## Code of Conduct
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
[email protected] with any additional questions or comments.


## Security issue notifications
If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue.
Please review the adopted [code of conduct](CODE_OF_CONDUCT.md) and make sure you follow the guidelines.


## Licensing

See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution.
See the [LICENSE](LICENSE) file for our project's licensing. By contributing, you agree that your contributions will be licensed under the existing license.
16 changes: 16 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
MIT License

Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of
Expand All @@ -13,3 +15,17 @@ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Copyright 2023 LocalStack. All Rights Reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39 changes: 39 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export AWS_ACCESS_KEY_ID ?= test
export AWS_SECRET_ACCESS_KEY ?= test
export AWS_DEFAULT_REGION=us-east-1
SHELL := /bin/bash

## Show this help
usage:
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'

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

## Deploy the RDS Serverless Application to LocalStack
deploy:
bash deploy.sh

## Start LocalStack in detached mode
start:
localstack start -d

## 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)

## 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

.PHONY: usage install deploy start stop ready logs
Loading

0 comments on commit af50aaf

Please sign in to comment.