Can I use CloudWatch Logs to trigger a Lambda function?

0

I'm working on a POC where I want to use the Amazon CloudWatch Logs (custom logs generated from the Amazon EC2 Instance) to trigger an AWS Lambda function based on a certain output is captured in the CloudWatch Logs. Is it possible to trigger Lambda based on CloudWatch Logs? If it's possible, provide me with the relevant documentation /procedure.

Example: Custom logs captured in the CloudWatch Log stream are similar to the following:

        ASCS Node: TRUE		ASCS Status: Running
        ASCS Node: TRUE		ASCS Status: Running
        ASCS Node: TRUE		ASCS Status: Running

I want to trigger a Lambda function when the following condition is true:

       ASCS Node: TRUE		ASCS Status: **Stopped**
AWS
질문됨 4년 전3857회 조회
1개 답변
1
수락된 답변

It's possible to trigger a Lambda from based on a matching pattern in the CloudWatch Logs. Instead of using the CloudWatch Logs subscription filters, do the following:

  1. Create metric filter from your Log group. For Filter Pattern, enter the pattern that you want to capture (in your sample : Status: **Stopped**). For more information, see Publishing numerical values found in log entries.
  2. Create an Amazon SNS topic and integrate your Lambda function there. For more information, see Tutorial: Using AWS Lambda with Amazon Simple Notification Service.
  3. Create CloudWatch Alarm to monitor the metric you created in step #1. For more information, see Create a CloudWatch alarm based on a static threshold.

Keep the following in mind when defining the alarm:

  • For Period, select a sufficient time range (Example: 10 seconds).
  • For Statistic, select Sum.
  • For Threshold type, select Static.
  • For Define the alarm condition, select Greater > threshold.
  • For Define the threshold value, select 0
  • Configure the alarm's action as the SNS topic you created earlier.
AWS
전문가
Tedy_T
답변함 4년 전
profile picture
전문가
검토됨 한 달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠