Creating an AWS CloudWatch subscription filter with a Lambda function
AWS CloudWatch subscription filters allow you to limit log event notifications to certain log groups, so that only the subscribers to a specific log group receive CloudWatch notifications. For this purpose, you can use an AWS Lambda function.
Before you begin
About this task
The AWS article
Example 2: Subscription filters with AWS Lambda
served as the basis for the following procedure.
Procedure
- In a web browser, open the CloudWatch console at:
- Click Create function.
- Select Author from scratch.
- From the Runtime drop-down list, select Python 3.11.
- In the Function name field, enter a name for the function.
- Under Permissions, select the proper execution role. You might have to expand the Change default execution role section first.
- Click Create function. You see a page with the selected function name as the title. On the lower half of page, you find a tabbed notebook labeled Source code. The Code tab is visible. On that tab, you find two editor windows.
- In the window with the title /lambda_function.py, write or paste your function code. You can use and modify the sample code provided in Lambda sample code for subscription filter.
- Click the Configuration tab.
- Under General configuration on the left, select Triggers.
- Click Add trigger
- From the Trigger configuration drop-down list, select CloudWatch Logs.
- From the Log groups drop-down list, select the log group that you want to associate with your filter.
- In the Filter name field, enter a name for your filter.
- Click Add.