Sitemap
4 min readFeb 16, 2023

--

AWS — SSL Certificate Expiration Alerts Using Lambda

This solution is mostly recommended for certificates that are managed by third-party certificates managers (eg: GoDaddy, Comodo, The SSL Store, etc…). It also can be used to monitor other public SSL certificates that are deployed or the AWS Certificate manager deployed SSL certificates.

Here is a solution using AWS Lambda service to monitor SSL certificate expiration alerts based on days left to get warning/critical alerts.

High-level Solution Overview

Press enter or click to view image in full size

Services Used:

1. AWS Lambda

2. AWS Cloud watch

3. AWS SNS

Implementation instructions:

First Setup the SNS Topic

Note: All the AWS services have been deployed in us-east-1 region.

1. Log in to the AWS console and open the SNS dashboard.

Click > Topics > Create topic

Press enter or click to view image in full size

2. Create an SNS topic to get the alerts. To create a topic please follow the steps in the provided screenshot.

Select > Standard

Name > ssl_cert_expire_sns

Display name — optional > ssl_cert_expire_sns

Click > Create topic

Press enter or click to view image in full size
Press enter or click to view image in full size

3. To get the emails we need to subscribe(add) the email address in the topic created below.

Select the topic and click > Create Subscribe

Press enter or click to view image in full size

Topic ARN > (Keep Default)

Protocol Select > Email

Endpoint: legionlenovointel@gmail.com (email that you're defining)

Click > Create Subscription

Press enter or click to view image in full size

Now you will get the confirmation email from AWS to receive emails from the topic. Go through the email and open the provided link in the email to subscribe.

4. Go to Lambda Service Dashboard > Click on the left panel “Functions” and Click “Create Function” select the Author from scratch (Lambda>Functions>Create function>Author from scratch)

Press enter or click to view image in full size

· Function Name: SSL-Cert-Expiry-Alert-Function (You can give your own function name)

· Runtime: Python 3.9

· Execution role: Create a New role from template(s)

· Role Name: SSL-Cert-Expiry-Alert-Role (you can give your own role name)

· Policy Templates: SNS publish policy

· Click > “Create function”

Press enter or click to view image in full size
Press enter or click to view image in full size

· Now Edit the function Code Section.

· Code entry type: Edit Code inline

· Runtime: Python 3.9

· Copy the function code from this GitHub URL https://github.com/aasheriff/ssl_cert_expiration_alert and past it into the lambda_function.py in the AWS lambda function. Click > “Deploy”

Press enter or click to view image in full size

Note: The script will produce warning alerts on the 50th and 40th and 30th day and critical alerts starting 15th and 20th day till you renew the SSL certificate.

Edit the code to update the SNS Topic ARN that was created initially.

Press enter or click to view image in full size

Add the domains you want to monitor:

Click on “Configuration” > “Environment Variables” > “Edit”

Variable Key needs to be domain_1 and the value will be your domain to monitor, as a sample I have used GitHub.com.

Press enter or click to view image in full size
Press enter or click to view image in full size
Press enter or click to view image in full size

5. Create a schedule event using CloudWatch to call the above Lambda function on daily basis.

Go to Cloudwatch > Expand “Events“ in left panel > Click on > “Rules” > Click “Create rule”

Press enter or click to view image in full size

· Event source: Select > “Schedule” Fixed rate of 1 and select > “Days”

· Target: select > “Lambda Function” > Function Select > ”SSL-Cert-Expire-Alert-Function”

· Click > “Configure Details”

Press enter or click to view image in full size

Name: “ssl_alerts_cw”

Click > “Create Rule”

Press enter or click to view image in full size

6. Editing the alert email body:

  • Go to the lambda function and in the left panel create a new file called message.txt and edit if needed.
Press enter or click to view image in full size

How to test, update the code line number 54 value from 15 to 500 and click deploy. Then after that run a test, and you will receive an alert to the subscribe email. (Refer to the Sample mail Alert).

Alert mail sample:

Sample:

Press enter or click to view image in full size

--

--

Amman Sheriff
Amman Sheriff

Written by Amman Sheriff

Cloud Infra | AWS SA & SYSOPS | IBM Spectrum Protect (TSM) | EMC Storage's | Netapp | VMware | Linux | Windows

Responses (1)