Skip to content

AWS Lambda script to check if a URL is responding and log response times and failures to Cloudwatch

License

Notifications You must be signed in to change notification settings

ciaran-finnegan/checkURL

Repository files navigation

checkUrl

Author: Ciaran Finnegan Version: 0.0.1

description

Node.js Lambda function that tests the availability of a web URL. Targets are specified in a json object passed to the event handler, urlChecker.checkUrl

In AWS Lambda console set handler to urlChecker.checkUrl and configure a Cloudwatch event trigger to supply a json object specifying the URLs to be checked on a schedule e.g.

{ "My google test URL": "http://google.com", "My glimps test URL": "http://glimps.in", "My test URL that will fail" : "http://google.com/xyz" }

  • Pass if a 2xx code is returned by a url (http or https).
  • Fail on any other error (e.g. URL not found or other http error code)*/

Implementation Notes

Sample Error Codes

Installation

  • Create a new Security Group

    • Name, urlChecker-out, Description urlChecker
    • Inbound rules none
    • Outbound rules, Protocol: TCP Ports: 0 - 65535 Destination: 0.0.0.0/0, Protocol DNS: Port: 53 Destination 0.0.0.0/0 (adjust as required)
  • Create IAM Role

    • Name, Lambda-urlChecker
  • Create a new lambda function called urlChecker

    • Description 'Checks URLs and logs to Cloudwatch'
    • Code entry type, zip file
    • Runtime, Node.js 8.10
    • Handler, urlChecker.checkURL
    • Memory 128MB
    • Timeout, 2 minutes (adjust as required)
    • Execution Role, Lambda-urlChecker
    • Network, choose applicable VPC
    • Subnets, choose applicable subnets
    • Security Groups, (urlChecker) | urlChecker-out
    • Concurrency, use unreserved amount
  • Create Cloudwatch Rule

    • Fixed rate of 5 minutes
    • Add Target, Lambda function, urlCheck
    • Configure Dashboard
      • to be completed
    • Configure Alarms
      • e.g. UrlNotResponding >= 1 for 2 datapoints within 10 minutes
      • to be completed

Enhancements

Update to pass configuration parameters for each URL e.g.

{ "url": "http://aws.amazon.com, "method": "GET", "timeout": 2000, "followRedirect": true, "maxRedirects": 5 }

Pass proxy configuration as a parameter

Also, test that this works

Automate creation of dashboards & alerts

About

AWS Lambda script to check if a URL is responding and log response times and failures to Cloudwatch

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published