[AWS Lambda] Scheduling Events with AWS Lambda (a.k.a. Lambda cron jobs)

Source: Internet
Author: User
Tags cloudwatch

Learn how to create AWS LAMBDA functions This execute on a scheduled interval and much like a cron job would. In this lesson we'll create a LAMBDA function that checks for a string of text on a website to verify the website are up and operational. The lambda function logs to CloudWatch Metrics and sends a notification e-mail using an SNS queue if the check fails.

Create a lambda function: (WebTest)

Exports.handler =function(event, context) {varHTTP = require (' http '); varOptions ={host:' Staticsite.willbutton.co '    }        varregex =/hello world/;//which'll falid        varCB =function(response) {varstr = ""; Response.on (' Data ',function(chunk) {str+=Chunk;                }); Response.on (' End ',function(){            if(Regex.test (str)) {Console.log ("WEBSITE PASSED"); Context.succeed (' yech! '); }Else{Console.log ("WEBSITE FAILED"); Context.fail (' Boo '); }})} http.request (options, CB). end ();

Then go to "Service" and "SNS":

Create a new topic:give the name "Webstiedown".
Then "Create a new Subscription":

It'll send you a confrim email.

Then go to the "Service"-"Cloud Watch"

"Create a Alarm"-"Select Lambda metrics"--config options, select error type

Save it.

Then later we need CloudWatch event source, so ' create new rule ': point to the lambda function

Save it.

Go the lambda function, add a new event Source:

Now it'll run the lambda function every 5 mins to check whether the website are in good condition. If anything wrong, it'll fire SNS-e-mail to send you a email.

[AWS Lambda] scheduling Events with AWS Lambda (a.k.a. Lambda cron jobs)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.