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 →Mastering Closed-Loop Incident Response: Connect AWS DevOps Agent to OpenSearch
In today's fast-paced cloud environments, effective incident response is crucial. Connecting the AWS DevOps Agent to OpenSearch using the Model Context Protocol (MCP) creates a closed-loop system that enhances detection and investigation. This integration allows for real-time correlation of logs and traces, driving faster root cause analysis.
Unlocking Observability: How Amazon CloudWatch Omni Transforms Application Monitoring
Amazon CloudWatch Omni is here to revolutionize how you observe your applications. With AI-powered insights and seamless integration of existing telemetry, it streamlines troubleshooting like never before. Discover how it can enhance your incident response process.
Unlocking AI Observability with Amazon CloudWatch Omni
Amazon CloudWatch Omni revolutionizes observability for generative AI workloads by providing a unified, app-centric experience. With features like Trace Explorer and built-in evaluators, it helps you measure and improve AI performance effectively.
Get the daily digest
One email. 5 articles. Every morning.
No spam. Unsubscribe anytime.