Skip to content

mentorpal/mentor-lrs

Repository files navigation

Mentorpal LRS API (using serverless - AWS Node.js Typescript)

For detailed instructions, please refer to the documentation.

Installation/deployment instructions

Requirements: NodeJS lts/gallium (v.16). If you're using nvm, run nvm use to ensure you're using the same Node version in local and in your lambda's runtime.

Using NPM

  • Run npm i to install the project dependencies
  • Run npm run deploy:dev to deploy to the dev environment

Test your service

This blueprint contains a single lambda function triggered by an HTTP request made on the provisioned API Gateway REST API /hello route with GET method. Requesting any other path than /hello with any other method than POST will result in API Gateway returning a 403 HTTP error code

⚠️ As is, this blueprint, once deployed, opens a public endpoint within your AWS account resources. Anybody with the URL can actively execute the API Gateway endpoint and the corresponding lambda. You should protect this endpoint with the authentication method of your choice.

Locally

In order to test the hello function locally, run the following command:

  • npx sls invoke local -f hello

Check the sls invoke local command documentation for more information.

Remotely

$ curl https://api.devmentorpal.org/lrs/hello
{"message":"Hello Serverless World!","event":{"...}}     

Project structure

The project code base is mainly located within the src folder. This folder is divided in:

  • functions - containing code base and configuration for your lambda functions
  • libs - containing shared code base between your lambdas
.
├── src
│   ├── functions               # Lambda configuration and source code folder
│   │   ├── hello
│   │   │   ├── handler.ts      # `Hello` lambda source code
│   │   │   ├── mock.json       # lambda input parameter, if any, for local invocation
│   │   │   └── schema.ts       # lambda input event JSON-Schema
│   │   │
│   │   └── index.ts            # Import/export of all lambda configurations
│   │
│   └── libs                    # Lambda shared code
│       └── apiGateway.ts       # API Gateway specific helpers
│       └── lambda.ts           # Lambda middleware
│
├── package.json
├── serverless.yml              # Serverless service file
├── tsconfig.json               # Typescript compiler configuration
├── tsconfig.paths.json         # Typescript paths
└── webpack.config.js           # Webpack configuration

3rd party libraries

  • middy - middleware engine for Node.Js lambda. This template uses http-json-body-parser to convert API Gateway event.body property, originally passed as a stringified JSON, to its corresponding parsed object
  • @serverless/typescript - provides up-to-date TypeScript definitions for your serverless.ts service file
  • license-check-and-add - allows you to quickly add and remove license headers to specified files

Advanced usage

Any tsconfig.json can be used, but if you do, set the environment variable TS_NODE_CONFIG for building the application, eg TS_NODE_CONFIG=./tsconfig.app.json npx serverless webpack

About

No description, website, or topics provided.

Resources

License

Unknown and 2 other licenses found

Licenses found

Unknown
LICENSE
Unknown
license-config.json
Unknown
license-ignore.txt

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •