Mastering Log Group-Level Subscription Filters in AWS
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
$C:\>aws kinesis create-stream --stream-name "RootAccess" --shard-count 1aws 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"aws iam create-role --role-nameCWLtoKinesisRole--assume-role-policy-document file://~/TrustPolicyForCWL-Kinesis.jsonWhen 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 docsSimple, affordable cloud — VMs, Kubernetes, and managed databases in minutes. Trusted by 600,000+ developers. Spin up a Droplet in 60 seconds.
Try DigitalOcean →Autonomous Incident Resolution with AWS DevOps Agent and Datadog MCP Server
Tired of manual incident management? The AWS DevOps Agent and Datadog MCP Server automate incident resolution, learning from your environment to prevent future issues. Discover how this powerful combination can transform your operations.
Unlocking Root Cause Analysis with AWS DevOps Agent's Multi-Agent Reasoning
Root cause analysis can be a nightmare in complex systems. AWS DevOps Agent leverages a multi-agent architecture to streamline incident investigations, using a topology graph to provide crucial context throughout the lifecycle.
Automate Root Cause Analysis with AWS DevOps Agent and Datadog
Root cause analysis can be a time-consuming process, but it doesn't have to be. With the AWS DevOps Agent, you can automate investigations triggered by Datadog alerts, correlating signals across observability backends in minutes.
Get the daily digest
One email. 5 articles. Every morning.
No spam. Unsubscribe anytime.