https://github.com/tux86/my-player-performance-api
A highly available serverless API with Lambda and Node.js
https://github.com/tux86/my-player-performance-api
apigateway lambda nodejs rest-api serverless-framework typescript
Last synced: 25 days ago
JSON representation
A highly available serverless API with Lambda and Node.js
- Host: GitHub
- URL: https://github.com/tux86/my-player-performance-api
- Owner: tux86
- Created: 2022-06-30T09:10:50.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-08-22T13:17:03.000Z (almost 4 years ago)
- Last Synced: 2023-03-09T01:26:36.098Z (over 3 years ago)
- Topics: apigateway, lambda, nodejs, rest-api, serverless-framework, typescript
- Language: TypeScript
- Homepage:
- Size: 521 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# My Player's Performance API
Yet another serverless ☁️ API with **Lambda** and **Node.js**
## Getting started!
Make sure **node 14.x** and **yarn** are installed.
```shell
$ git clone git@github.com:tux86/my-player-performance-api.git
$ cd my-player-performance-api
$ yarn install
```
## Creating the environment file
Inside this project root directory, a template environment file **.env.template** is available for you.
Make a copy of this file to **.env.dev** using cp command as below.
```shell
$ cp .env.template .env.dev
```
now open **.env.dev** using a text editor, the content should look like this :
```dotenv
AWS_PROFILE=****
AWS_REGION=eu-west-1
DEPLOYMENT_BUCKET_NAME_PREFIX=
ENDPOINT_URL=****
NODE_ENV=development
```
Update the content by setting a value for each the following variables
- **AWS_PROFILE:** your aws profile name (admin credentials required)
- **AWS_REGION:** the aws region (example: eu-west-1)
- **DEPLOYMENT_BUCKET_NAME_PREFIX:** optional (The default value is the service name).
` 🚨 IMPORTANT 🚨 : You should set a prefix if the bucket name is not available because bucket name is unique across all AWS accounts`
- **ENDPOINT_URL:** the dataset endpoint URL
## Running project locally (offline mode)
Use the following commands inorder to start the project locally.
```shell
$ yarn build # build project
$ yarn start # start serverless offline mode
```
Once started, you will see a message in the console (as shown below) indicating a successful startup
```shell
┌─────────────────────────────────────────────────────────────────────────────────┐
│ │
│ GET | http://127.0.0.1:3000/players │
│ POST | http://127.0.0.1:3000/2015-03-31/functions/listPlayers/invocations │
│ GET | http://127.0.0.1:3000/players/{id} │
│ POST | http://127.0.0.1:3000/2015-03-31/functions/getPlayerById/invocations │
│ │
└─────────────────────────────────────────────────────────────────────────────────┘
```
## Running Tests
```shell
$ yarn test
```
## Deploy service to AWS cloud
To make a deployment to AWS cloud, you need to execute the following command:
```shell
$ yarn sls:deploy
```
Verify that the deployment completed successfully. You should see the following in the console :
```shell
✔ Service deployed to stack my-player-performance-api-dev (32s)
endpoints:
GET - https://abcdef1234.execute-api.eu-west-1.amazonaws.com/players
GET - https://abcdef1234.execute-api.eu-west-1.amazonaws.com/players/{id}
functions:
listPlayers: my-player-performance-api-listPlayers-dev (6.3 MB)
getPlayerById: my-player-performance-api-getPlayerById-dev (6.3 MB)
Monitor all your API routes with Serverless Console: run "serverless --console"
Done in 36.32s
```
## Remove the deployed service
```shell
$ yarn sls:remove
```
**That's All Folks !** 😉