/C4-Serverless

Primary LanguageJavaScriptMIT LicenseMIT

Cloudniite is a JavaScript library that helps you as a developer optimize and monitor your serverless application performance and metrics on AWS Lambda. We chose AWS because it has an exceptional ecosystem of cloud products and a huge community of developers that are passionate about the future of serverless. We integrate seamlessly with your application to help you ensure your customers are having a fast and responsive experience. We do this by helping you organize and monitor event-driven AWS Lambda functions. If you are unfamiliar with AWS Lambda, no need to worry, we will cover the core concepts in the next section.

Learn how to use Cloudniite in your own project.

How do you optimize AWS Lambda functions?

Amazon has to prepare or spin-up, new virtual servers to run your code. This startup time only happens when your functions haven't been run in a while. For Amazon, it doesn't make sense to keep your function running on a server if no one is using it. So, after a period of time, if your function isn't used, Amazon will "destroy" the server it is living on. This function will now be considered "cold". Cold functions take longer to run and will leave your users waiting longer for a response because of the time it takes to spin up a server to host the function.

Developers have been using simple timers to "warmup" their functions so that they stay running and available for users. This solution works but we believed there could be a smarter way to manage and keep your Lambda functions warm and performant.

Cloudniite Examples.

Below are a few examples of how you could use our library to minimize cold starts, organize your functions into groups and optimize your application to ensure it responds quickly to user actions.

AWS Lambda Function Groups

Cloudniite lets you easily group your Lambda functions however you like. If you want to make sure all the Lambda functions associated with your landing page are warmed up, simply create a tag group passing in the functions you would like to be grouped together.

cloudniite.createTagGroup("#LandingPage","SignupUser","EmailSubscription")

Then, whenever you want to warmup the LandingPage functions, just call our method passing in the tag group name.

lambdaController.warmupTagGroup(null, "#LandingPage"); 

Installation

Cloudniite is available as the cloudniite package on npm.

npm install --save cloudniite

Getting Started

When creating a function:

  • Add an if statement to check if cloudniite has invoked the function.
  • After else statement fill in the function as you normally would.
  • This will optimally warm-up the function without running the entire function

In a text editor:

exports.handler = function(event, context, callback) {
    if (event.source === "Cloudniite-Warmup") {
        callback(null,"Warmup");
    } else {
         //your function
    }
}

On AWS:

o alt text Make sure both yaml and lambda files are in the same folder.

Authors

  • Linda Harrison - Initial work - GitHub
  • Stephen Grable - Initial work - GitHub
  • Muhammad Sheikh - Initial work - GitHub

License

Cloudniite is MIT licensed.