use js to generate serverless.yml
a util help you to generate serverless framework deploy file fluently
# global cli
npm i -g serverless-config-generator
yarn global add serverless-config-generator
//or
npm i -D serverless-config-generator
yarn add -D serverless-config-generator
if you install globally you could run
# in your target dir
sls-gen
# serverless.js to serverless.yml
sls-gen -i serverless.layer.js -o serverless.layer.yml
or write jscode in Node.js
const { generateSync, generate } = require('serverless-config-generator')
const path = require('path')
// default
generateSync()
//or
async main(){
await generate()
}
// process.cwd() serverless.js => serverless.yml
generateSync({
input:path.resolve(__dirname,'./lib/xxx.js'),
output:{
dir:path.resolve(__dirname,'./layer'),
filename:'serverless.layer.yml'
}
})
params | type | default |
---|---|---|
input | string |
path.resolve(process.cwd(),'serverless.js') |
output | string/Object |
path.resolve(process.cwd(),'serverless.yml') |
output.dir | string |
undefined |
output.filename | string |
undefined |