AWS Certified Solutions Architect – Professional
CloudWatch Logs cross-account subscriptions for SAP-C03
The CloudWatch Logs User Guide says cross-account delivery goes through a destination in the receiving account. The destination points to a Kinesis data stream or a Firehose stream and carries an access policy. Each sending account creates a subscription filter, or one account-level policy per Region, that targets the destination in the same Region.
What a subscription filter does
A subscription delivers a real-time feed of log events to a Kinesis data stream, an Amazon Data Firehose stream or an AWS Lambda function. The filter pattern decides which events are delivered. Events reach the receiving resource soon after ingestion, usually in less than three minutes, compressed with gzip.
A log group can have up to five subscription filters. An account can have one account-level subscription filter per Region. Subscriptions are supported only for log groups in the Standard log class.
Delivery is at least once, so duplicates can occur. When the destination returns a retryable error, CloudWatch Logs keeps retrying for up to 24 hours. CloudWatch Logs also has a separate centralization feature that replicates log data from multiple accounts and Regions into a central location.
Cross-account delivery through a destination
The receiving account creates a destination with put-destination. It names the target stream and an IAM role in the receiving account that lets CloudWatch Logs put data into that stream. The receiving account then attaches an access policy that says who may subscribe.
The access policy can name individual sender accounts. It can instead allow a whole organization by using a wildcard principal restricted with the aws:PrincipalOrgID condition. With the organization form, new accounts need no change on the receiving side. AWS warns against a wildcard principal without that condition.
The sending account creates the subscription filter with the destination's ARN. If the destination has an organization access policy, the sender must also pass the ARN of an IAM role in the sending account with --role-arn. Without it, PutSubscriptionFilter fails with an error saying a role ARN is required.
The log group and the destination must be in the same Region. The stream behind the destination can be in a different Region. Log groups in two Regions therefore need a destination in each Region, and both destinations can point at one stream.
Account-level subscription filter policies
PutAccountPolicy with the SUBSCRIPTION_FILTER_POLICY type creates one policy that applies to the log groups that exist in the account and to log groups created later. Each account can have one such policy per Region.
In the same account, the policy can target a Kinesis data stream, a Firehose stream or a Lambda function. Across accounts, the only supported target is a logical destination created with PutDestination, backed by Kinesis Data Streams or Firehose. A same-account stream needs a role ARN in the policy. A cross-account destination does not. The caller needs iam:PassRole for every target except a Lambda function.
An account-wide policy can create a loop. If a log group that receives logs from the delivery workflow is itself subscribed, its events are delivered, which produces more logs, which are delivered again. AWS's example is a Lambda function that processes the S3 objects Firehose writes. Ingestion, Firehose and S3 charges all rise.
The selection criteria prevent this. For a subscription filter policy the only supported form is LogGroupName NOT IN [...], which excludes the listed log groups. AWS says to consider log groups from Lambda, Step Functions, Fargate and VPC flow logs that are part of the workflow.
Where the exam catches people
- Believing an access policy that allows the organization is all a sender needs: with an organization access policy the subscription filter must also pass a role ARN, or the call fails.
- Believing one destination serves log groups in every Region: the destination must be in the log group's Region. Only the stream behind it can be in another Region.
- Believing an account-level policy can target a Lambda function in another account: cross-account targets are logical destinations backed by Kinesis Data Streams or Firehose.
- Believing an account-level policy should include every log group: exclude log groups that belong to the delivery workflow, or the logs loop and ingestion charges grow.
- Believing the selection criteria can pick the log groups to include: for subscription filter policies only
LogGroupName NOT INis supported.