generate-serverless-files
v1.0.1
Published
This project helps to generate serverless files
Downloads
11
Readme
generate-serverless-files
This project helps to generate serverless files
This project is inspired by swagger-jsdoc and the post of @dwelch2344
installations
npm install --save generate-serverless-files
how It works
It parse the documentation in your files to give them to serverless when you use
serverless deploy
Getting Started
Write a js generator
create a js (serverless-dynamic.js
for example) file and put this code :
const parse = require("generate-serverless-files");
module.exports = () => {
return parse(["*.ts"]);
}
Include in the serverless.yml
In your main serverless.yml
file import the previously created file
service: example
provider:
name: aws
runtime: nodejs12.x
region: eu-west-3
memorySize: 128
timeout: 10
functions: ${file(./serverless-dynamic.js)}
Write the doc
in your code, writes the serverless configuration in the documentation
import {body, Controller, custom, header, Method, param, query} from "@igloobuster/aws_lambda_middleware/dist/Annotations";
@Controller({exports, json: true, router: new Router(middlewares)})
export class Example {
/**
* @serverless
* getExample:
* handler: routes/Example.getExample
* events:
* - http:
* path: /example
* method: get
*/
@Method()
private async getExample() {
return {Hello: "world"};
}
/**
* @serverless
* postExample:
* handler: routes/Example.postExample
* events:
* - http:
* path: /example
* method: post
*/
@Method()
private async postExample() {
return {Hello: "post to the world"};
}
}
All the lines bellow @serverless will be used for the configuration