Using subscription filters in Amazon CloudWatch Logs

Publish date: 2024-05-04

This Python example shows you how to create and delete filters for log events in CloudWatch Logs.

The scenario#

Subscriptions provide access to a real-time feed of log events from CloudWatch Logs and deliver that feed to other services, such as an Amazon Kinesis stream or AWS Lambda, for custom processing, analysis, or loading to other systems. A subscription filter defines the pattern to use for filtering which log events are delivered to your AWS resource.

In this example, Python code is used to list, create, and delete a subscription filter in CloudWatch Logs. The destination for the log events is a Lambda function. The code uses the AWS SDK for Python to manage subscription filters using these methods of the CloudWatchLogs client class:

For more information about CloudWatch Logs subscriptions, see Real-time Processing of Log Data with Subscriptions in the Amazon CloudWatch Logs User Guide.

All the example code for the Amazon Web Services (AWS) SDK for Python is available here on GitHub.

ncG1vNJzZmian6m8dHrAppizp56WxLR6wqikaK5hZLGwr9SmnKeskam2sLqOmqeiZ5yWwaa%2F02ierqGUmnykw4yer5qloKGybr%2FUm6qcqpmlwaq7zWadoqSkmr%2B0esetpKU%3D