DEV Community

Harish Aravindan
Harish Aravindan

Posted on

Serverless Endpoint Monitoring - check uptime of your app

Do you need to monitor your application endpoints and have a dashboard to check the detail - all this in a serverless way on AWS.
Let's see how it's done.

Solution Design
Ping Service Architecture

  • This setup creates a s3 webpage that takes in the required information for monitoring.
  • Backend contains a lambda to create eventbridge schedule (cron) and cloudwatch alarm.
  • The eventbridge schedule trigger will invoke a lambda to check the endpoint and update cloudwatch with custom metric of the response status code.

Requirements:

  • AWS knowledge of how to create lambda function | iam roles and s3 websites

Step 1 - Setup the Lambda Function

Clone the code from github

https://github.com/uptownaravi/ping_service.git
Enter fullscreen mode Exit fullscreen mode

Create Lambda function checkEndpoint that will check the endpoint and update cloudwatch metric.
Use file checkEndpoint.py from the app folder and for the role for this lambda use the iam policy document in the file checkEndpointPolicy.json.

Replace all the url / region name / account number in the code.

Create Lambda function addPingEndpoint using the file addPingEndpoint.py in app folder and the related iam policy in addPingEndpointPolicy.json

This Lambda will be creating the eventbridge schedule with the payload of the requested service to check. That will be show in the target section once created. This is the connecting part that tells the checkEndpoint Lambda what url to check and which cloudwatch metric to update.

Enable Function URL for addPingEndpoint function as we need that to be added to the s3 website. Allow headers for accept and content-type
CORS needs to be enabled - check steps after s3 bucket for this.

Step 2 - S3 Website Creation

Next create s3 website using the code in web folder
In the file app.html update the function-url to the lambda function url created in the previous step.
Steps to create a website in s3 https://docs.aws.amazon.com/AmazonS3/latest/userguide/HostingWebsiteOnS3Setup.html

Note for CORS in the addPingEndpoint Lambda function add the CORS origin of function url as the s3 bucket like - http://.s3-website..amazonaws.com
this will make sure the function url can be used from the s3 website.

After deploying the website and enabling static hosting
below page should be visible if you visit http://.s3-website..amazonaws.com

webpage with details

Step 3 - Test the solution

Enter the details in the webpage
Service Name: name of the service to monitor
Endpoint: URL to check
Details: description of the service
cron: cron expression of the schedule to check ( AWS Document https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-cron-expressions.html )

after submitting we get the message

success message after form submission

Check your EventBridge Schedules and CloudWatchAlarm / Metric Dashboard to see the results

Event Bridge Schedule

metric namespace

Cloud watch metric showing the custom metric status code for the AnalyticsApp which we added the details in the webpage

metric graph

and in alarms

cloudwatch alarm

This can be done for many services and all those will be available as custom metrics in their namespace.

Note There are no actions added to this alarm.
Add the required SNS alerts if required, to get the update on downtime of your endpoints.

Top comments (0)