https://github.com/vitaee/nodeserverless
simple example serverless api with aws
https://github.com/vitaee/nodeserverless
aws nodejs serverless-framework
Last synced: 3 months ago
JSON representation
simple example serverless api with aws
- Host: GitHub
- URL: https://github.com/vitaee/nodeserverless
- Owner: Vitaee
- Created: 2022-05-19T14:59:09.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-09-28T07:53:14.000Z (almost 4 years ago)
- Last Synced: 2024-12-26T03:42:17.811Z (over 1 year ago)
- Topics: aws, nodejs, serverless-framework
- Language: TypeScript
- Homepage:
- Size: 553 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Serverless Framework AWS TypeScript Example
This project contains express mysql rest api project with aws lambda.
## Usage
Check simple instructions below.
### Before Deployment
For env variables in production, i used s3 bucket. Simply upload your file to s3 then via github actions you can download from s3 to project directory to read variables.
- Setup AWS CLI for your [OS](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-quickstart.html)
- Upload your example file below;
```
touch env.json
nano env.json
```
```json
{
"DB_NAME":"PROD_DB_NAME",
"DB_USER":"PROD_DB_USER",
"DB_PASS":"PROD_DB_PASS",
"DB_HOST":"PROD_DB_HOST",
"DB_PORT":3306
}
```
Finally,
```
aws s3 cp env.json s3://awsbucketvitae/
```
### Deployment
In order to deploy the project, you need to run the following command:
```bash
$ serverless deploy
```
After running deploy, you should see output similar to:
```bash
Deploying aws-node-express-api to stage dev (us-east-1)
✔ Service deployed to stack aws-node-typescript-dev (112s)
- https://7cqzatbj16.execute-api.us-east-1.amazonaws.com/
functions:
api: aws-node-express-api (806 B)
```
### Invocation
After successful deployment, you can test the deployed api by using the following command:
```bash
curl https://7cqzatbj16.execute-api.us-east-1.amazonaws.com/
```
Which should result in response similar to the following:
```json
{"msg":"Express server with TypeScript!"}
```
### Local development
You should create env.json file according to .env.example:
```json
{
"DB_NAME":"slsnode",
"DB_USER":"root",
"DB_PASS":"123456",
"DB_HOST":"172.17.0.3",
"DB_PORT":3306
}
```
Then simply call this command;
```bash
npm run dev
```
Which should result in response similar to the following:
```
Starting Offline at stage dev (us-east-1)
Offline [http for lambda] listening on http://localhost:3002
ANY | http://localhost:3001/{default*}
Server ready: http://localhost:3001 🚀
```