Skip to main content
This lesson shows how to stream CloudWatch Logs into an Amazon Kinesis Data Stream for near real-time processing. Follow the steps in order to configure the stream, an IAM role, and a CloudWatch Logs subscription filter. Quick overview
  • Create a Kinesis Data Stream.
  • Create an IAM role that CloudWatch Logs can assume (trust policy).
  • Attach a permission policy granting kinesis:PutRecord and kinesis:PutRecords to the specific stream ARN.
  • Create a CloudWatch Logs subscription filter pointing to the Kinesis Data Stream.
Table of contents
  • Creating the Kinesis Data Stream
  • IAM role and trust policy for CloudWatch Logs
  • Permission policy: allow PutRecord and PutRecords
  • Creating the CloudWatch Logs subscription filter
  • Start streaming and verification
  • Summary and references
Creating the Kinesis Data Stream Kinesis Data Streams ingest streaming data and make it available for near real-time consumers. In the AWS console, open Kinesis → Kinesis Data Streams → Create data stream. Choose a name (for example, LogStream). Key options to consider:
  • Capacity model: on-demand (recommended for simplicity) or provisioned.
  • Record distribution strategy: user-specified when you need explicit shard assignment; use auto if ordering is not required.
  • Maximum record size: keep the default unless you have special requirements.
After creation, the stream may take a few minutes to become active.
A screenshot of the AWS Management Console showing an Amazon Kinesis data stream named "LogStream" with a green banner saying it was successfully created. The page shows the Data stream summary (status Active, retention period, ARN and creation time).
If you expect bursts of traffic or variable throughput, the on-demand capacity mode reduces the need to manage shard scaling. Use provisioned mode when you need predictable throughput and shard-level control.
Overview: CloudWatch Logs needs permission to send events to Kinesis To forward logs to a Kinesis stream, CloudWatch Logs must be able to assume an IAM role and use that role to write to the stream. This requires two distinct policies:
  • Trust policy: permits the CloudWatch Logs service principal (logs.amazonaws.com) to assume the role (via sts:AssumeRole).
  • Permission policy: grants the role kinesis:PutRecord and kinesis:PutRecords on the specific Kinesis stream ARN.
Creating the IAM role and trust policy Create a new role in the IAM console. For CloudWatch Logs, use a custom trust policy such as the example below. This defines who (the CloudWatch Logs service) can assume the role. Example trust policy (JSON):
This trust policy answers “who can assume this role”: the CloudWatch Logs service.
A screenshot of the AWS IAM "Create role" workflow showing the "Add permissions" step, with options to "Use existing policy" or "Create inline policy" and a permissions policies search area. The browser tab bar and AWS console header are visible.
Adding the permission policy: allow PutRecord and PutRecords to your Kinesis stream Attach a permission policy that allows the role to write to your Kinesis stream. Limit the Resource to the exact stream ARN to follow least-privilege principles. Example permission policy (replace <KINESIS_STREAM_ARN> with your stream ARN):
Example ARN format for a Kinesis stream (replace account and region):
Note the difference between the two policy types:
  • Trust policy: controls who may assume the role (CloudWatch Logs via sts:AssumeRole).
  • Permission policy: controls what the assumed role may do (e.g., kinesis:PutRecord on the specific stream).
Always reference the exact Kinesis Data Stream ARN in the permission policy. Restricting permissions to a specific resource is a security best practice.
Name the role (for example, CloudWatchLogsToKinesisRole), verify both the trust and permission policies, and create the role. Create the CloudWatch Logs subscription filter With the Kinesis stream and IAM role created, configure a subscription filter on the CloudWatch Logs log group you want to forward. In CloudWatch:
  • Open Log Management → Log groups.
  • Select the target log group (or create one).
  • From the Actions menu, choose to create a Kinesis subscription filter.
A screenshot of the AWS CloudWatch console showing the LogGroup2 details page. The Actions menu is expanded, displaying subscription filter creation options (Create Kinesis, OpenSearch, Data Firehose, Lambda) and control buttons like "View in Logs Insights" and "Search log group."
Subscription filter configuration Configure the subscription with these values:
  • Destination: Select the Kinesis Data Stream (same account) — e.g., LogStream.
  • Permissions: Select the IAM role you created (e.g., CloudWatchLogsToKinesisRole) rather than letting the console create a role automatically.
  • Distribution method:
    • By log stream ensures records from each log stream map consistently to shards.
    • Random will distribute events across shards (acceptable when ordering per log stream is not required).
A screenshot of the AWS CloudWatch console on the "Create Kinesis subscription filter" page showing the "Distribution method" section. The "By log stream" option is selected and a "Random" option is listed below.
A screenshot of the AWS CloudWatch console showing the "Create Kinesis subscription filter" page, with a "Configure log format and filters" panel and form fields for Log format and Subscription filter pattern. The browser tabs and AWS account banner are visible at the top.
Subscription filter name Provide a meaningful filter name (1–512 characters). If left blank, the console will show a validation error.
A screenshot of the AWS CloudWatch console on the "Create Kinesis subscription filter" page showing input fields for a subscription filter pattern and name. The subscription name field is highlighted with a validation error saying filter names must be between 1 and 512 characters.
Start streaming After creating the subscription filter, CloudWatch Logs will begin evaluating incoming log events and forwarding matching events to the Kinesis Data Stream using the role you supplied. The subscription will appear on the log group details page. Example CloudWatch log group ARN (reference):
Example KMS key ARN (if used for server-side encryption):
Screenshot of the AWS CloudWatch console showing the "LogGroup2" details page, including the ARN, creation time, subscription filters, and config options with buttons like "Actions" and "Search log group."
Verification tips
  • Check the subscription filter is listed under the log group details.
  • Monitor Kinesis metrics (IncomingRecords, PutRecord/PutRecords success/failure) in CloudWatch to confirm data flow.
  • If using encryption, ensure the IAM role can use the KMS key if cross-service encryption permissions are required.
Summary and exam notes
  • CloudWatch Logs subscription filters can forward log events to Kinesis Data Streams for near real-time processing.
  • Required IAM configuration:
    • Trust policy allowing logs.amazonaws.com to assume the role (sts:AssumeRole).
    • Permission policy allowing kinesis:PutRecord and kinesis:PutRecords on the specific Kinesis stream ARN.
  • Subscription filters can optionally filter events; leaving the pattern blank forwards all events.
  • Use By log stream distribution when per-log-stream ordering is important.
References

Watch Video