Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/davidroman0o/serverless-moleculer
Serverless Framework handler for Moleculer
https://github.com/davidroman0o/serverless-moleculer
moleculer serverless-framework
Last synced: 2 months ago
JSON representation
Serverless Framework handler for Moleculer
- Host: GitHub
- URL: https://github.com/davidroman0o/serverless-moleculer
- Owner: davidroman0O
- Created: 2018-11-15T15:06:29.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-12-12T13:45:15.000Z (about 6 years ago)
- Last Synced: 2024-04-27T02:03:29.275Z (8 months ago)
- Topics: moleculer, serverless-framework
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/serverless-moleculer
- Size: 62.5 KB
- Stars: 21
- Watchers: 4
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
![Moleculer logo](http://moleculer.services/images/banner.png)
# Serverless-Moleculer
Serverless Framework & Moleculer !
Note : available for the impatients :smile: ! I'll add a better documentation and a start kit for beginner (with serverless-fuck-you-4kb too).
# Install
You already know it : `npm install --save serverless-moleculer`
# How to use it
On your `serverless.yml` file, create a new function :
```yaml
HelloWorld:
name: "serverless-moleculer-hello-world"
handler: handler.HelloWorld
memorySize: 256
timeout: 30
events:
- http:
path: /
method: any
cors:
origin: '*'
headers:
- Content-Type
- X-Amz-Date
- Authorization
- X-Api-Key
- X-Amz-Security-Token
- X-Amz-User-Agent
allowCredentials: false
```On your function `handler.js` that contain your basic lambda handler, replace everything with :
```javascript
const Moleculer = require("serverless-moleculer");module.exports = Moleculer({
settings: {
json: true, // Do you want the event.body to be parsed? By default, it's a string
service: {
log: false, // Do you want all logs of the the lib? Set false in prod plz
listAll: false // Do you want to list all actions loaded? Set false in prod plz
},
response: {
log: false, // Do you want to see the response log? Set false in prod plz
}
},
// You got a plugin and you want to trigger it first?
plugins: [
(event, context, callback) => {
if (event.source === 'serverless-plugin-warmup') {
context.callbackWaitsForEmptyEventLoop = false;
callback(null, {
message: "Just warm"
});
return true;
}
}
],
// Every global moleculer middlewares are loaded here
middlewares: [
require("./services/someMiddlware")
],
services: [
"services/global/health-to-sqs.js",
require("./services/global/ping"),
],
lambdas: {
// Mandatory, we use it you create your function reference base on the "handler: handler.HelloWorld" line
"HelloWorld": {
services: [
"services/math.service.js",
require("./services/allo.service"),
],
// Mandatory, we use the process.env.AWS_LAMBDA_FUNCTION_NAME to load quickly your lambda !!
name: "serverless-moleculer-hello-world",
// Optional : action or handler(ctx) -> NOT BOTH
action: "service.someAction",
// OR
handler(ctx) {
this.logger.info("Hello World");
return "Response for the body";
}
},
}
})```