Serverless framework
Serverless is your toolkit for deploying and operating serverless architectures. Focus on your application, not your infrastructure.
Serverless framework making it a breeze to use cloud function, like google cloud function or aws lambda function, im personally using lambda function and i was amazed how brelinet I felt about the idea after my first lambda function.
The configuration for this kind of function can be hard and often confusing! to solve that, Serverless framework created, to develop a cloud function easily and make it more intuitive. the framework use yml function just like docker.
**Usage **
- configure aws-cli account (aws configure).
- npm i -g serverless.
- to create a new function with babel transpiler, offline support and local env variable file, use serverless install --url https://github.com/niradler/serverless-nodejs-starter/tree/dev --name my-project
- cd my-project.
- create env.yml (optional).
- serverless.yml is the configuration file.
- check out the hello function in the handler.js this is the application root file. exportconsthello=async (event, context, callback) => { constresponse= { statusCode:200, body:JSON.stringify({ message:
</span>Go Serverless v1.0! <span class="pl-s1"><span class="pl-pse">${</span>(<span class="pl-k">await</span><span class="pl-en">message</span>({ time<span class="pl-k">:</span><span class="pl-c1">1</span>, copy<span class="pl-k">:</span><span class="pl-pds">'</span>Your function executed successfully!<span class="pl-pds">'</span>}))<span class="pl-pse">}</span></span><span class="pl-pds">
, input:event, }), }; callback(null, response); }; constmessage= ({ time, ...rest }) =>newPromise((resolve, reject) =>setTimeout(() => { resolve(</span><span class="pl-s1"><span class="pl-pse">${</span><span class="pl-smi">rest</span>.<span class="pl-smi">copy</span><span class="pl-pse">}</span></span> (with a delay)<span class="pl-pds">
); }, time *1000) ); - to run the function locally use, serverless offline start
- to deploy just use serverless deploy
Simple as that! serverless architecture is getting very popular you should not miss it, this is definitely the future!