This project monitors a specific URL to match a predefined regular expression. In case of a match it will send an email to the configured email address.
The services makes use of the AWS Lamda stack to schedule the app every two minutes.
This is an example of creating a function that runs as a cron job using the serverless schedule
event. For more information on schedule
event check out the Serverless docs on schedule.
Schedule events use the rate
or cron
syntax.
rate(value unit)
value
- A positive number
unit
- The unit of time. ( minute | minutes | hour | hours | day | days )
Example rate(5 minutes)
For more information on the rate syntax see the AWS docs
cron(Minutes Hours Day-of-month Month Day-of-week Year)
All fields are required and time zone is UTC only.
Field | Values | Wildcards |
---|---|---|
Minutes | 0-59 | , - * / |
Hours | 0-23 | , - * / |
Day-of-month | 1-31 | , - * ? / L W |
Month | 1-12 or JAN-DEC | , - * / |
Day-of-week | 1-7 or SUN-SAT | , - * ? / L # |
Year | 192199 | , - * / |
Read the AWS cron expression syntax docs for more info on how to setup cron
REGEX='REGEX' URL='https://example.com' SENDGRID='APIKEY' EMAIL='recipient@example.com' node --inspect-brk test.js
In order to deploy the endpoint you simply run
serverless deploy
Result is something like this:
Serverless: Packaging service...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading service .zip file to S3 (1.47 KB)...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
..............
Serverless: Stack update finished...
Service Information
service: check-website-for-string
stage: dev
region: us-east-1
stack: check-website-for-string-dev
resources: 7
api keys:
None
endpoints:
None
functions:
cron: check-website-for-string-dev-cron
layers:
None
Regex
An email will be sent out if the provided regular expression is machted. If you want to negate a regular expression, you can do it like this ^((?!not available).)*$
.
AWS CloudWatch Logs
Serverless CLI
To see your cron job running tail your logs with:
serverless logs --function cron --tail