Every time I work on my website either updating WordPress or changing the theme, I seem to lose my the code snippet for tracking my web traffic. So when I go to look at the statistics it regularly has been showing no data, 0 active users. So, in this blog, I’m going to detail how to create an alert system, so you can get an Email or SMS notification. The monitoring system I am detailing has 2 programs, one to check the website is available and the other sends an alert it the code for traffic analysis is missing.

Login to AWS

You will need an Amazon AWS account before you can access the https://aws.amazon.com/console/

If you have not used AWS before, then the very first thing you will want to do is choose your region. I recommend using a location that is very close to your website or if you are like me and hosting on Amazon, then in the same region. If you want to send SMS notifications, then you may have no choice but to choose another region that is supporting SMS.

Step 1: Setup The Notifications

Search for and go into the Amazon Simple Notification Service (SNS).

If it is your first time here you will see an introduction screen, just click on the blue “getting started” button, then create the topic.

You want to create 2 new topics

website-offline

missing-analytics

You will be prompted for the “topic name” and if you want to setup SMS notification, then you need to come up with a 10 character “display name” too.

To get email notifications you’ll need to subscribe to the notification topic.

Note Frankfurt currently doesn’t support SMS. Choose the “protocol” Email and provide an address that will be used to get notifications.

You will need to go into your Email account and click on the subscribe button.

The final step is to set up permissions to allow the Lambda, which will be checking the website. This is an important step or you will be getting AuthorizationErrorException messages, which actually lead to me wanting to write this article. It seems this setup is so trivial that nobody seems to have written about it in some time. I am actually also learning by documenting this and you can see I below I just give Everyone on the AWS account access. If you have a larger organisation, this might not be such a good idea.

You might also want to allow other users to subscribe, in which case you’ll be adapting the settings under “allow these users to subscribe to this topic”.

I’ve only screen provided screenshots for setting up one topic. So repeat the above steps until you have both ready.

Step 2: Setup Lambda Functions

The two programs you’ll need can be found in my GitHub repository https://github.com/neilspink/aws-lambda-website-status-checking

Using the console search for “Lambda”

In the Lambda management console, you now create new Lambda functions

website-offline

missing-analytics

When you create the first function you’ll also need to create a new custom role. This would be used to give your Lambda function permissions to do things on your account. We just need a blank one for this time.

When you choose ‘create a custom role’ you should immediately see the following screen, where you need to provide a good name for your role.

Click on the create the function button and you’ll be looking at the Lambda editor, which can initially be overwhelming. When you see this JUST Scroll down.

Then you can copy and paste in the Python script from https://github.com/neilspink/aws-lambda-website-status-checking (click on RAW view of the files when you want to copy)