Schedule and Configure Lambda to Notify you..

April 8, 2016 | Comments(2) |

In the era of Dev-ops, continuous integration and deployment,  AWS Lambda provides you with various features, that will help you automate your needs. Lambda  is a compute service from Amazon Web Services, which performs actions on various available services of AWS, based on the program code that you upload for execution. It can be triggered by events or with a scheduled event provided by CloudWatch.

In this blog, we are going to see step-by-step process of

  • Creating Lambda Function
  • Integrating Lambda With CloudWatch (Scheduled Event)
  • Creating SNS Topic and Subscriptions
  • Integrating CloudWatch With SNS for Notification

Why use Lambda?

Lambda will be an effective solution, when there are events that are need to be performed in a periodic manner. It will also help in infrastructure automation.

Example Use Cases.

  • Taking AMIs or Snapshots in a regular interval of time.
  • Adding 2 servers morning at 8.00am when no of servers running is lesser than 30. etc,.

Cost Comparision

For a scheduled running of a program that triggers the API’s, a dedicated Linux Cron machine is commonly used.

Though the program runs few times a day, the instance must be running throughout the year.

Cost of a (t1.micro) EC2 machine running for a month = $ 14.64 m1


Cost of running the same for a year =$ 14.64 * 12 = $ 175.56


Points to Ponder

  • You are responsible for your Linux Cron instance and must take necessary steps for Scaling, Patching, Administration
  • You must also ensure that, another machine is backing up when cron instance goes down.

Most often, when your Lambda function runs for few minutes, few times a day, it will come under the free tier*.

For Lambda Pricing and free tier information, click the following link.

Creating Lambda Function

Important Note:

  • Although AWS Lambda can perform actions in various regions, CloudWatch and Lambda are region-specific.
  • So make sure that CloudWatch Rule is in the same region, with the created Lambda Function.

Integrating Lambda With CloudWatch

Although, Lambda is basically Event-driven, Lambada can also be Scheduled to take place in a particular time or particular interval of time.



Integrating CloudWatch With SNS

CloudWatch can trigger SNS, if an event is completed or when there is a change in the state of EC2 or when an action is performed in Auto Scaling Group or even when an API call.

For example, we are configuring SNS  to send Email and Email-Json notification when a Lambda function gets executed or when an event is completed successfully.


Important Note:

  • CloudWatch is region-specific. So make sure that CloudWatch Rule is in the same region, with the created SNS Topics.
  • If Lambda performs events in various regions, CloudWatch and SNS have to be created for every region to get all notifications

Configuring CloudWatch to Trigger SNS

You will receive mail with many parameters, that will help you identify how the lambda function got invoked and other key attributes, to the configured mail account. It will help you to analyze your logs and keep track of events.

mThus, whenever Lambda gets triggered in a scheduled manner through CloudWatch, we will receive notification.

Please comment and share if you like the article. Feel free to ask your questions and provide your valuable suggestions below.  


2 Responses to “Schedule and Configure Lambda to Notify you..”

Leave a Reply