Git Product home page Git Product logo

aws-lambda-http-check's Introduction

Lambda http check

Lambda function to check specific http endpoint, and report on it's availability.

Optionally, it can record metrics to CloudWatch.

Inputs

All inputs are either defined as environment variables or as part of event data. Event data will take priority over environment variables

ENDPOINT - url to be checked

METHOD - http method to use, defaults to GET

PAYLOAD - http payload, if POST or PUT used as method

TIMEOUT - timeout to use for http requests, defaults to 120s

HEADERS - list of percentage sign (%) separated headers to send to target server, defaults to empty list.

USER_AGENT - If specified, will be added to the HEADERS. An example is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Base2/Lambda

REPORT_RESPONSE_BODY - set to 1 if you wish to report on response body, 0 otherwise, 0 otherwise, defaults to 0

REPORT_AS_CW_METRICS - set to 1 if you wish to store reported data as CW custom metrics, 0 otherwise, defaults to 1

CW_METRICS_NAMESPACE - if CW custom metrics are being reported, this will determine their namespace, defaults to 'HttpCheck'

BODY_REGEX_MATCH - if CW custom metrics are being reported, this will enable ResponseBodyRegexMatch metric to be published as well, with value determined by success of matching response body against regular expression contained within this option

STATUS_CODE_MATCH - report whether http status code is equal to given status code or not. If this option is not present, it won't be reported upon. Defaults to empty

FAIL_ON_STATUS_CODE_MISMATCH - if checking for status code match treat mismatch as failure, ie report Available: 0

Outputs

By default, following properties will be rendered in output Json

Reason - Reason

Available - 0 or 1

TimeTaken - Time in ms it took to get response from remote server. Default timeout is 2 minutes for http requests.

StatusCode - Http Status Code

ResponseBody - Optional, by default this won't be reported

ResponseBodyRegexMatch - Optional, if BODY_REGEX_MATCH option is provided

StatusCodeMatch - Optional, if STATUS_CODE_MATCH options is provided

Dependencies

Lambda function is having no external dependencies by design, so no additional packaging steps are required for deploying it, such as doing pip install [libname]

CloudWatch Metrics

In order to get some metrics which you can alert on, REPORT_AS_CW_METRICS and CW_METRICS_NAMESPACE environment variables are used. Following metrics will be reported

  • Available - 0 or 1, whether response was received in timely manner, indicating problems with network, DNS lookup or server timeout

  • TimeTaken - Time taken to fetch response, reported in milliseconds

  • StatusCode - HTTP Status code received from server

  • ResponseBodyRegexMatch - optional this will report 1 or 0 if BODY_REGEX_MATCH option is specified. 1 is reported if response body matches regex provided, or 0 otherwise.

  • StatusCodeMatch - *optional& this will report 1 or 0 if STATUS_CODE_MATCH options is specified. 1 is reported if response status code matches code provided, or 0 otherwise

Deployment

You can either deploy Lambda manually, or through AWS SAM CLI. If the SAM CLI is being chosen as method of deployments use command below, while making sure that you have setup access to your AWS account.

build the lambda

sam build

deploy the template

sam deploy --guided

If you are setting up your Lambda function by hand, make sure it has proper IAM permissions to push Cloud Watch metrics data, and to write to CloudWatch logs

Testing

To test function locally with simple Google url (default), run following

sam local invoke Check

Optionally, for complicated example take a look at test/ipify.json file

sam local invoke Check --event test/ipify.json 

Debugging

If you wish to see debug output for http request, set HTTP_DEBUG environment variable to '1'. This can't be controlled through event payload.

Schedule execution

Pull requests are welcome to serverless project to deploy CloudWatch rules in order to schedule execution of Http Checking Lambda function.

aws-lambda-http-check's People

Contributors

btisdall avatar guslington avatar jaredbrook avatar kyletbase2 avatar lohgannash avatar tarunmenon95 avatar toshke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aws-lambda-http-check's Issues

Stack 'aws-python3-dev' does not exist

I'm getting the following error

Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Creating Stack...
Serverless: Checking Stack create progress...
...
Serverless: Stack create finished...

Serverless Error ---------------------------------------

Stack 'aws-python3-dev' does not exist

Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com

Your Environment Information ---------------------------
Operating System: darwin
Node Version: 12.18.1
Framework Version: 2.10.0 (standalone)
Plugin Version: 4.1.1
SDK Version: 2.3.2
Components Version: 3.3.0

Support for temporary http status codes

Use-Case: Someone manually puts an endpoint into some sort of maintenance mode so instead of return a 200 it now returns a 302.

Right now this triggers a status code metric to change for 0 to 1. It would be nice to be able to specify a grace period for this temporary status code.

Another option would be to output a different metric value when the temporary status code is being returned.

This would then be able to not trigger alarms unless the temporary status code remains in-place for greater than grace period

Allow reading payload parameters from secret / parameter store

In case of authorization headers needing to be sent to HTTP(s) endpoint - they should be stored in secret store, rather than passed unencrypted as payload to lambda function. Suggestion is that if any value in payload is in following forms

  • aws:smps("path")
  • aws:sm("store.key")

They should be replaced with actual secret value from AWS System Manager Parameter Store (first form), or AWS Secrets Manager (2nd form).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.