Mobile Monitoring Solutions

Search
Close this search box.

Amazon CloudWatch Alarms Can Now Directly Trigger Lambda Functions

MMS Founder
MMS Renato Losio

Article originally posted on InfoQ. Visit InfoQ

AWS recently announced that Amazon CloudWatch alarms now support AWS Lambda functions as an action for state changes. This new feature enables developers to automate remediation actions when detecting an unhealthy resource.

Designed to be the easiest way to automate custom actions on alarm state changes, the new option allows developers to invoke a Lambda function directly when a CloudWatch alarm changes to an OK, ALARM, or INSUFFICIENT_DATA state.

The PutMetricAlarm now supports invoking the latest version of a Lambda function (arn:aws:lambda:region:account-id:function:function-name), a specific version of the function (arn:aws:lambda:region:account-id:function:function-name:version-number) or using an alias (arn:aws:lambda:region:account-id:function:function-name:alias-name). According to the documentation, when a Lambda function is configured as an alarm action, CloudWatch delivers a JSON payload to the Lambda function when it invokes it, including alarmData, previousState, and configuration information.

Invoking a Lambda function is not the sole option available in CloudWatch Alarms: notifying one or more people or services by sending a message to an SNS topic remains the most popular choice. Additionally, alarms can perform actions to scale an Auto Scaling group and alarms based on EC2 metrics can execute EC2 actions, such as stopping, terminating, rebooting, or recovering an instance. Finally, when alarms go into an ALARM state, they can create operational work items in Systems Manager Ops Center or incidents in the Systems Manager Incident Manager.

The cloud provider emphasizes the ability to combine this new option with existing ones:

You can use the fact that multiple actions are allowed for an alarm to send an email when a threshold is breached, and then another when the breaching condition ends. This helps you verify that your scaling or recovery actions are triggered when expected and are working as desired.

The community’s response has been overwhelmingly positive, with Luc van Donkesgoed, Principal Engineer at PostNL, writing:

Another loooooong (like 9 years long) awaited feature is here: CloudWatch Alarms can now directly call Lambda Functions!

Antonio Lagrotteria, principal cloud engineer and architect at Nordea, describes it as one of the “top 3 post-reinvent announcements that people have been waiting for almost a decade and should shadow most of reinvent announcements.” On a Reddit thread, user yourparadigm suggests instead that the change is not significant and emphasizes that it was already possible to trigger a Lambda function indirectly:

Is putting an SNS Topic in front that big of a deal?

In a separate announcement, the cloud provider revealed that CloudWatch Network Monitor is now generally available. This new feature facilitates monitoring network availability and performance between AWS and on-premises environments and it supports hybrid monitors for networking built with AWS Direct Connect and AWS Site-to-Site VPN.

CloudWatch Alarms support for Lambda actions is available in all regions and standard Cloudwatch pricing applies.

About the Author

Subscribe for MMS Newsletter

By signing up, you will receive updates about our latest information.

  • This field is for validation purposes and should be left unchanged.