OpsCanary
awsobservabilityPractitioner

Mastering Log Group-Level Subscription Filters in AWS

5 min read AWS DocsJul 26, 2026Reviewed for accuracy
Share
PractitionerHands-on experience recommended

Log group-level subscription filters are crucial for enabling real-time log processing in AWS. They allow you to send logs directly to services like Kinesis Data Streams, AWS Lambda, and Amazon OpenSearch Service. This capability helps you maintain observability over your applications by processing logs as they are generated, rather than waiting for batch jobs to run. The logs sent through these filters are base64 encoded and compressed using gzip, ensuring efficient transfer and storage.

To set up a subscription filter, you first need to create a destination stream in Kinesis. After that, you must create an IAM role that grants CloudWatch Logs permission to put data into your stream. Finally, you establish the subscription filter that will start sending real-time log data from your log group to the stream. For instance, you can create a stream with the command $C:\>aws kinesis create-stream --stream-name "RootAccess" --shard-count 1. Then, set up the subscription filter with a command like aws logs put-subscription-filter --log-group-name "CloudTrail/logs" --filter-name "RootAccess" --filter-pattern "{$.userIdentity.type = Root}" --destination-arn "arn:aws:kinesis:region:123456789012:stream/RootAccess" --role-arn "arn:aws:iam::123456789012:role/CWLtoKinesisRole".

In production, you need to be mindful of potential throttling issues. If your stream doesn't have enough shards to handle the volume of log data, it will throttle, and failed deliveries will be dropped after 24 hours. To mitigate this, consider using random distribution for your subscription filter and monitor your stream with CloudWatch metrics. Also, using on-demand capacity mode for Kinesis Data Streams can help accommodate fluctuating workloads. Always ensure your filter patterns align with your stream's capacity to avoid overwhelming it.

Key takeaways

  • Create a Kinesis stream before setting up a subscription filter.
  • Use base64 encoding and gzip compression for efficient log transfer.
  • Monitor CloudWatch metrics to identify throttling issues.
  • Specify random distribution to mitigate throttling risks.
  • Adjust filter patterns to match the capacity of your Kinesis stream.

Why it matters

In production, real-time log processing enhances your ability to respond to issues quickly, improving application reliability and user experience. By leveraging subscription filters, you can gain insights into system behavior as it happens.

Code examples

shell
$C:\>aws kinesis create-stream --stream-name "RootAccess" --shard-count 1
shell
aws logs put-subscription-filter \ --log-group-name "CloudTrail/logs" \ --filter-name "RootAccess" \ --filter-pattern "{$.userIdentity.type = Root}" \ --destination-arn "arn:aws:kinesis:region:123456789012:stream/RootAccess" \ --role-arn "arn:aws:iam::123456789012:role/CWLtoKinesisRole"
shell
aws iam create-role --role-nameCWLtoKinesisRole--assume-role-policy-document file://~/TrustPolicyForCWL-Kinesis.json

When NOT to use this

The official docs don't call out specific anti-patterns here. Use your judgment based on your scale and requirements.

Want the complete reference?

Read official docs

Test what you just learned

Quiz questions written from this article

Take the quiz →
DigitalOceanSponsor

Simple, affordable cloud — VMs, Kubernetes, and managed databases in minutes. Trusted by 600,000+ developers. Spin up a Droplet in 60 seconds.

Try DigitalOcean →

Get the daily digest

One email. 5 articles. Every morning.

No spam. Unsubscribe anytime.