Certopolis

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 IN is supported.

Written from these sources

Try 3 questions on this

Pick an answer to see why each option is right or wrong.

  1. A company has 45 member accounts in AWS Organizations, and each account runs workloads in us-east-1 and eu-central-1. A central archive account has an Amazon Data Firehose stream in us-east-1 that writes to an Amazon S3 bucket, where an S3 Lifecycle rule moves objects to S3 Glacier Deep Archive for 7 years. The archive account also has an AWS Lambda function that writes any records it receives into the stream. Every log event from every log group in both Regions, including log groups created later, must reach the stream. No stream or bucket may be added. Which combination of steps should a solutions architect take to meet these requirements? (Select TWO.)

    Right. In the game that’s Renown for your Operational Excellence and Automation building.

    Not that one: D,E is right. In the game your Operational Excellence and Automation building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    And a destination must be in the same Region as the log groups that subscribe to it, although the stream behind it may be in another Region. So the archive account creates one destination in us-east-1 and one in eu-central-1, both pointing at the us-east-1 Firehose stream, and every member account sets an account-level policy in each Region that targets that Region's destination. The existing Lifecycle rule then handles the 7-year archive.

    Written from docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CreateSubscriptionFilterFirehose-Account.html

  2. A company has 60 member accounts in AWS Organizations, all in us-east-1, and adds about five accounts each month. A security account owns an Amazon Data Firehose stream that writes to Amazon S3. Each member account's AWS CloudTrail log group in Amazon CloudWatch Logs must stream to that Firehose stream. The security team will not edit any resource in the security account when a member account is added, and an AWS CloudFormation StackSet configures every member account in the same way. Which solution will meet these requirements?

    Right. In the game that’s Renown for your Operational Excellence and Automation building.

    Not that one: A is right. In the game your Operational Excellence and Automation building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    Granting the whole organization in that policy means new accounts need no change in the security account. The behaviour that catches teams out is on the sending side: when the destination trusts an organization rather than named accounts, each subscription filter must pass the ARN of an IAM role in the sending account that CloudWatch Logs can assume, so that CloudWatch Logs can check the sender's right to subscribe. Without the role, creating the filter fails. The StackSet can create that role and the filter in every new account.

    Written from docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CreateSubscriptionFilterFirehose.html

  3. A company's analytics account has about 400 Amazon CloudWatch Logs log groups, and product teams create new ones every week. Every product team's log events must reach an Amazon Data Firehose stream in the same account, which writes them to an Amazon S3 bucket. An S3 event notification invokes an enrichment AWS Lambda function for each new object, and the function writes its own logs to CloudWatch Logs. The platform team owns the enrichment function and an AWS CloudTrail log group. The company wants no per-log-group setup and no unexpected growth in ingestion charges. Which combination of steps should a solutions architect take to meet these requirements? (Select TWO.)

    Right. In the game that’s Renown for your Operational Excellence and Automation building.

    Not that one: A,B is right. In the game your Operational Excellence and Automation building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    For a Firehose destination the policy names an IAM role that CloudWatch Logs assumes to put records into the stream, and whoever creates the policy needs iam:PassRole for it. Safety is about the enrichment function. It runs because the subscription delivered objects to S3, and it writes logs; if its log group is subscribed, those logs become new objects that invoke it again, without end, and ingestion charges climb. The selection criteria in the policy exist to leave such log groups out.

    Written from docs.aws.amazon.com/AmazonCloudWatch/latest/logs/SubscriptionFilters-AccountLevel.html

Ask for something