lambda-healthcheck-express

    0.1.0 • Public • Published

    dynamic forms healthcheck npm

    Summary

    Supports AWS lambdas implemented in NodeJs using express for middleware and routing. Once added as a middleware function, the healthcheck module provides a GET endpoint that responds with a JSON body and appropriate HTTP status codes to indiate if the lambda is healthy or not.

    Getting started

    Required change to package.json for all health checks

    The healthcheck module reads a file version.json at the root of the lambda distribution files. Modify package.json by adding a version command to create this file during the build phase:

    #package.json
    #Adds a version command that writes out the version from the parent package.json and writes it to a file in the deployment folder
    "scripts": {
        ...,
        "build": "mkdir -p dist && <current build> && npm run version",
        "version": "jq '. | {version: .version}' package.json > ./dist/version.json"
    }
    

    The healthcheck module requires a file named version.json to exist at the root of the files deployed as the lambda. This file is read and the version is returned in the healthcheck response as the first check. If the version.json does not exist, the heathcheck will return a warn status as the initial status.

    Default lambda health check

    #Server.js
    const HealthCheck = require('healthCheck');
    ...
    app.use('/healthCheck', new HealthCheck().handler())
    

    Custom health check

    #Server.js
    const { HealthCheck, Check } = require('healthCheck');
    ...
    const options = {
        checks: [new Check("custom-check", "pass")]
    };
    
    app.use('/healthCheck', new HealthCheck(options).handler())
    

    Development

    Use TDD

    Testing

    npm run test
    

    Deployment

    Set auth token environment variable:

    export NPM_TOKEN=<token>
    

    Publish NPM

    npm publish
    

    Keywords

    none

    Install

    npm i lambda-healthcheck-express

    DownloadsWeekly Downloads

    2

    Version

    0.1.0

    License

    ISC

    Unpacked Size

    64.1 kB

    Total Files

    18

    Last publish

    Collaborators

    • mijreinhold