-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d43090
commit 41f65c1
Showing
29 changed files
with
10,536 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
examples/serverless-localstack-with-s3-and-dynamodb/.env.example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Deployment Configuration | ||
SERVICE_NAME=serverless-localstack-example | ||
|
||
PROGRAMS_S3_BUCKET_NAME=serverless-localstack-bucket |
4 changes: 4 additions & 0 deletions
4
examples/serverless-localstack-with-s3-and-dynamodb/.env.local
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Deployment Configuration | ||
SERVICE_NAME=serverless-localstack-example | ||
|
||
PROGRAMS_S3_BUCKET_NAME=serverless-localstack-bucket |
22 changes: 22 additions & 0 deletions
22
examples/serverless-localstack-with-s3-and-dynamodb/.eslintrc.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module.exports = { | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
project: './tsconfig.json', | ||
tsconfigRootDir: __dirname, | ||
}, | ||
plugins: ['@typescript-eslint/eslint-plugin'], | ||
extends: ['plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'], | ||
root: true, | ||
env: { | ||
node: true, | ||
jest: true, | ||
}, | ||
ignorePatterns: ['.eslintrc.js'], | ||
rules: { | ||
'@typescript-eslint/interface-name-prefix': 'off', | ||
'@typescript-eslint/explicit-function-return-type': 'off', | ||
'@typescript-eslint/explicit-module-boundary-types': 'off', | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
'@typescript-eslint/no-empty-function': 'off', | ||
}, | ||
}; |
11 changes: 11 additions & 0 deletions
11
examples/serverless-localstack-with-s3-and-dynamodb/.eslitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# /node_modules/* in the project root is ignored by default | ||
# build artefacts | ||
dist/* | ||
coverage/* | ||
node_modules/* | ||
logs/* | ||
prod/* | ||
.husky/* | ||
.github/* | ||
tools/ | ||
localstack/volume |
46 changes: 46 additions & 0 deletions
46
examples/serverless-localstack-with-s3-and-dynamodb/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# compiled output | ||
/dist | ||
/node_modules | ||
.tsbuildinfo | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# OS | ||
.DS_Store | ||
|
||
# Tests | ||
/coverage | ||
/.nyc_output | ||
|
||
# IDEs and editors | ||
/.idea | ||
.project | ||
.classpath | ||
.c9/ | ||
*.launch | ||
.settings/ | ||
*.sublime-workspace | ||
|
||
# IDE - VSCode | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json | ||
|
||
# env | ||
.env | ||
.envrc | ||
|
||
# Serverless Framework | ||
.serverless | ||
.build | ||
.webpack | ||
.local-s3 | ||
.volume |
4 changes: 4 additions & 0 deletions
4
examples/serverless-localstack-with-s3-and-dynamodb/.husky/pre-commit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
pnpm run lint-staged |
4 changes: 4 additions & 0 deletions
4
examples/serverless-localstack-with-s3-and-dynamodb/.husky/pre-push
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
pnpm run type-check |
4 changes: 4 additions & 0 deletions
4
examples/serverless-localstack-with-s3-and-dynamodb/.lintstagedrc.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"*.{js,jsx,ts,tsx}": ["prettier --write", "npm run lint:fix"], | ||
"*.{json,css,sass,scss,less,html,md,yml,yaml}": ["prettier --write"] | ||
} |
1 change: 1 addition & 0 deletions
1
examples/serverless-localstack-with-s3-and-dynamodb/.node-version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v18.15.0 |
8 changes: 8 additions & 0 deletions
8
examples/serverless-localstack-with-s3-and-dynamodb/.prettierignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# /node_modules/* in the project root is ignored by default | ||
# build artefacts | ||
dist/* | ||
coverage/* | ||
node_modules/* | ||
logs/* | ||
prod/* | ||
localstack/volume |
7 changes: 7 additions & 0 deletions
7
examples/serverless-localstack-with-s3-and-dynamodb/.prettierrc.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
semi: true, | ||
trailingComma: 'all', | ||
singleQuote: true, | ||
printWidth: 120, | ||
tabWidth: 2, | ||
}; |
93 changes: 93 additions & 0 deletions
93
examples/serverless-localstack-with-s3-and-dynamodb/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# Serverless LocalStack Example [![serverless](http://public.serverless.com/badges/v3.svg)](http://www.serverless.com) | ||
|
||
This project is a TypeScript based API generated using [create-awesome-node-app](https://www.npmjs.com/package/create-awesome-node-app). However, it is recommended to generate your own project using the command and following the options in the interactive menu. Please refer to the documentation for more information. | ||
|
||
We use Serverless Framework to do production ready deployments and local development using | ||
_serverless-offline_. | ||
|
||
## Features | ||
|
||
- 🦾 [TypeScript](https://www.typescriptlang.org/) - Ensures type safety | ||
- 🌐 API Gateway - Build scalable and maintainable APIs | ||
- ⚙️ Configuration Management - Manage different environments and configurations | ||
- 📜 Logging - Implement logging for debugging and monitoring purposes | ||
- 🧪 Unit Testing - Write and execute unit tests to ensure code quality | ||
|
||
## Pre-packed with | ||
|
||
- [TypeScript](https://www.typescriptlang.org/) | ||
- [ESLint](https://eslint.org/) - JavaScript and JSX linting utility | ||
- [Prettier](https://prettier.io/) - Opinionated code formatter | ||
- [Husky](https://www.npmjs.com/package/husky) - Simplifies Git hooks setup | ||
- [lint-staged](https://www.npmjs.com/package/lint-staged) - Runs linters against staged git files, preventing 💩 from slipping into your code base! | ||
|
||
## Requirements | ||
|
||
- [Docker](https://www.docker.com/) | ||
- [Docker Composer](https://docs.docker.com/compose/) | ||
- [Node.js](https://nodejs.org/en/) 18 or later | ||
|
||
**You’ll need to have Node 18 or later on your local development machine** (but it’s not required on the server). You can use [fnm](https://github.com/Schniz/fnm) to easily switch Node versions between different projects. | ||
|
||
## Quickstart | ||
|
||
```sh | ||
# Setup NodeJs and install dependencies | ||
fnm use | ||
pnpm install | ||
|
||
# Run the Local Stack using Docker Compose | ||
docker-compose up -d | ||
|
||
# Run the application locally | ||
pnpm run sls:offline | ||
``` | ||
|
||
## Testing locally | ||
|
||
```sh | ||
curl -X POST http://localhost:3000/program --header 'Content-Type': 'application/json' --data '{ | ||
"content": "console.log(\"Hello World\");", | ||
"filePath": "example/file.js" | ||
}' | ||
``` | ||
|
||
Then run the following command to check the uploaded file: | ||
|
||
```sh | ||
# Set the AWS credentials | ||
export AWS_ACCESS_KEY_ID="dummy-value" | ||
export AWS_SECRET_ACCESS_KEY="dummy-value" | ||
|
||
# List the uploaded files | ||
aws --endpoint-url=http://localhost:4566 --no-verify-ssl s3 ls --recursive serverless-localstack-bucket | ||
# 2023-10-31 18:00:00 18 example/file.js | ||
``` | ||
|
||
## Development | ||
|
||
While developing, you will mostly rely on `pnpm run dev`; however, there are additional scripts available: | ||
|
||
| `pnpm run <script>` | Description | | ||
| ------------------- | ---------------------------------------------------------- | | ||
| `sls:offline` | Serves your app locally for development | | ||
| `format` | Formats the project using [Prettier](https://prettier.io/) | | ||
| `lint` | Lints the project for potential errors | | ||
| `lint:fix` | Lints the project and fixes all correctable errors | | ||
|
||
## Production | ||
|
||
Available scripts: | ||
|
||
| `pnpm run <script>` | Description | | ||
| ------------------- | ------------------------------------------------------ | | ||
| `sls:package` | Builds the application to the `.serverless/` directory | | ||
|
||
## Extra documentation | ||
|
||
You can find useful information such as project structure, available scripts and much more in the [docs](./docs) folder! | ||
|
||
## Recommended Resources | ||
|
||
We recommend checking out our awesome list of resources for learning about Serverless Framework, AWS Lambda, | ||
local development, and more. Check it out here: [Awesome NaN Labs](https://github.com/nanlabs/awesome-nan). |
45 changes: 45 additions & 0 deletions
45
examples/serverless-localstack-with-s3-and-dynamodb/compose.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
version: '3.9' | ||
|
||
services: | ||
localstack: | ||
image: localstack/localstack:1.0.3 | ||
ports: | ||
- '4566:4566' # LocalStack Gateway | ||
- '4510-4559:4510-4559' # external services port range | ||
# - "53:53" # DNS config (only required for Pro) | ||
# - "53:53/udp" # DNS config (only required for Pro) | ||
# - "443:443" # LocalStack HTTPS Gateway (only required for Pro) | ||
environment: | ||
- DEBUG=${DEBUG-} | ||
- PERSISTENCE=${PERSISTENCE-} | ||
- LAMBDA_EXECUTOR=${LAMBDA_EXECUTOR-} | ||
# - LOCALSTACK_API_KEY=${LOCALSTACK_API_KEY-} # only required for Pro | ||
- DOCKER_HOST=unix:///var/run/docker.sock | ||
- SERVICES=dynamodb,s3,sqs | ||
volumes: | ||
- localstack-data:/var/lib/localstack' | ||
- '/var/run/docker.sock:/var/run/docker.sock' | ||
networks: | ||
- localstack-net | ||
|
||
setup-resources: | ||
image: mesosphere/aws-cli:1.14.5 | ||
volumes: | ||
- ./localstack:/project | ||
environment: | ||
- AWS_ACCESS_KEY_ID=dummyaccess | ||
- AWS_SECRET_ACCESS_KEY=dummysecret | ||
- AWS_DEFAULT_REGION=us-east-1 | ||
entrypoint: /bin/sh -c | ||
command: /project/setup-resources.sh | ||
networks: | ||
- localstack-net | ||
depends_on: | ||
- localstack | ||
|
||
networks: | ||
localstack-net: | ||
driver: bridge | ||
|
||
volumes: | ||
localstack-data: |
25 changes: 25 additions & 0 deletions
25
examples/serverless-localstack-with-s3-and-dynamodb/docs/DEPLOYMENT.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Serverless Deployment | ||
|
||
[![serverless](http://public.serverless.com/badges/v3.svg)](http://www.serverless.com) | ||
|
||
We use Serverless Framework to do production ready deployments. | ||
|
||
## Requirements | ||
|
||
**You’ll need to have Node 18 or later on your local development machine** (but it’s not required on the server). You can use [fnm](https://github.com/Schniz/fnm) to easily switch Node versions between different projects. | ||
|
||
```sh | ||
fnm use | ||
pnpm install | ||
``` | ||
|
||
## AWS Lambda Deployment | ||
|
||
To deploy the app to AWS, you'll first need to configure your AWS credentials. There are many ways | ||
to set your credentials, for more information refer to the [AWS documentation](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html). | ||
|
||
Once set you can deploy your app using the serverless framework with: | ||
|
||
```sh | ||
npm run sls:deploy | ||
``` |
8 changes: 8 additions & 0 deletions
8
examples/serverless-localstack-with-s3-and-dynamodb/docs/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Extra Documentation | ||
|
||
This folder contains extra documentation for the project such us project structure, configuration, etc. | ||
|
||
## Resources | ||
|
||
- [Serverless Framework Documentation](https://www.serverless.com/) | ||
- [Deployment docs](./DEPLOYMENT.md) |
11 changes: 11 additions & 0 deletions
11
examples/serverless-localstack-with-s3-and-dynamodb/jest.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = { | ||
moduleFileExtensions: ['js', 'json', 'ts'], | ||
rootDir: 'src', | ||
testRegex: '.*\\.spec\\.ts$', | ||
transform: { | ||
'^.+\\.(t|j)s$': 'ts-jest', | ||
}, | ||
collectCoverageFrom: ['**/*.(t|j)s'], | ||
coverageDirectory: '../coverage', | ||
testEnvironment: 'node', | ||
}; |
2 changes: 2 additions & 0 deletions
2
examples/serverless-localstack-with-s3-and-dynamodb/localstack/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.env | ||
volume/ |
44 changes: 44 additions & 0 deletions
44
examples/serverless-localstack-with-s3-and-dynamodb/localstack/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# LocalStack | ||
|
||
It will execute the script `setup-resources.sh` to setup the resources. | ||
|
||
## Resources | ||
|
||
Once the docker compose is up, it will create the following resources: | ||
|
||
- [DynamoDB Table](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html) | ||
- [S3 Bucket](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) | ||
- [SQS Queue](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/welcome.html) | ||
|
||
## Testing | ||
|
||
From outside the container you can execute the following commands to test the service each service: | ||
|
||
- **DynamoDB** | ||
|
||
```sh | ||
$ aws --endpoint-url=http://localhost:4566 dynamodb list-tables | ||
{ | ||
"TableNames": [ | ||
"my_table" | ||
] | ||
} | ||
``` | ||
|
||
- **S3** | ||
|
||
```sh | ||
$ aws --endpoint-url=http://localhost:4566 s3 ls | ||
2022-08-08 03:16:01 example-bucket | ||
``` | ||
|
||
- **SQS** | ||
|
||
```sh | ||
$ aws --endpoint-url=http://localhost:4566 sqs list-queues | ||
{ | ||
"QueueUrls": [ | ||
"http://localhost:4566/000000000000/my_queue" | ||
] | ||
} | ||
``` |
Oops, something went wrong.