Certopolis

AWS Certified DevOps Engineer – Professional

CloudWatch Logs subscription filters and cross-account delivery

A subscription filter sends matching log events from a log group to Amazon Kinesis Data Streams, Amazon Data Firehose, AWS Lambda or Amazon OpenSearch Service. The CloudWatch Logs User Guide says cross-account delivery goes through a CloudWatch Logs destination that the recipient account creates, with an access policy naming who may send to it.

How is each subscription target authorized?

For a Kinesis data stream, you create an IAM role that CloudWatch Logs assumes, with a permissions policy that lets it put data into the stream. The role's ARN is passed with --role-arn when the subscription filter is created.

For a Lambda function there is no role on the filter. The function's own policy must allow the principal logs.amazonaws.com to call lambda:InvokeFunction, which aws lambda add-permission sets up with the log group as the source ARN.

Data sent through a subscription filter is compressed with gzip. Lambda receives it base64 encoded in the awslogs.data field. Kinesis records hold the gzip bytes.

How does cross-account delivery work?

The recipient account creates a destination. A destination has a name, a target ARN such as a Kinesis data stream, a role ARN that lets CloudWatch Logs put data into that stream, and an access policy that sets who is allowed to write to the destination. The recipient then shares the destination's ARN with the sender.

The sender account creates a subscription filter on its log group that points at the destination. The sender can be a single account or a whole organization. When the policy admits an organization, each sender account still needs its own subscription filter.

The log group and the destination must be in the same Region. The resource that the destination points to can be in a different Region.

What happens when the stream is throttled?

If a Kinesis data stream does not have enough shards for the log volume, delivery is throttled. Throttled deliveries are retried for up to 24 hours. After 24 hours the failed deliveries are dropped.

AWS lists four ways to reduce the risk. Set distribution to random on the filter, because the default distributes by log stream. Watch the DeliveryThrottling metric. Use on-demand capacity mode for the stream. Narrow the filter pattern to match the capacity of the stream.

Where the exam catches people

  • Believing a Lambda target needs a role on the subscription filter: Lambda is authorized by a resource-based permission for logs.amazonaws.com. Roles are for stream targets.
  • Believing the destination must be in the same Region as the stream: the destination must be in the same Region as the log group. The stream can be elsewhere.
  • Believing an organization-wide access policy creates the subscriptions: every sender account must still create its own subscription filter.
  • Believing throttled log deliveries are retried until they succeed: they are retried for up to 24 hours and then dropped.
  • Believing the sender account owns the destination: the recipient creates the destination and its role, and shares the ARN.

Written from these sources

Try 3 questions on this

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

  1. A DevOps team manages an Amazon CloudWatch Logs log group named /orders/app with an AWS CloudFormation template. The template must add two subscription filters to the log group. One sends every event to an Amazon Data Firehose stream that delivers to Amazon S3. The other sends ERROR events to an AWS Lambda function that opens tickets. The stream, the function and the log group are in the same account and Region. Company policy requires every grant to be scoped to this log group, this stream or this function. Which combination of steps will meet these requirements? (Select TWO.)

    Right. In the game that’s Renown for your Monitoring and Logging building.

    Not that one: C,D is right. In the game your Monitoring and Logging building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    For a Lambda target there is no role: the function itself must allow CloudWatch Logs to invoke it through a resource-based policy, which in CloudFormation is an AWS::Lambda::Permission with lambda:InvokeFunction and the log group's ARN as the source ARN. Both grants stay scoped to this stream, function and log group.

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

  2. A company acquired a business that runs its applications in four AWS accounts. The four accounts are not part of the company's organization in AWS Organizations and will stay separate for two years. Each account writes application events to an Amazon CloudWatch Logs log group named /app/events in eu-west-1. The company's security account runs an intrusion detection application that reads one Amazon Kinesis Data Streams data stream in eu-west-1. New events from all four log groups must reach that stream within minutes. Which combination of steps should the DevOps engineer take to meet these requirements? (Select THREE.)

    Right. In the game that’s Renown for your Monitoring and Logging building.

    Not that one: A,C,F is right. In the game your Monitoring and Logging building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    Because the four acquired accounts are outside the organization, the destination's access policy names their four account IDs and allows them to call logs:PutSubscriptionFilter on it. Each acquired account then creates its own subscription filter on /app/events and points it at the destination ARN. CloudWatch Logs forwards matching events soon after ingestion, usually within three minutes.

    Written from docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CrossAccountSubscriptions-Kinesis.html

  3. A company has 30 accounts in AWS Organizations with workloads in us-east-1 and eu-west-1. In every account and Region, a subscription filter on the /app/audit log group sends events to an Amazon CloudWatch Logs destination in a central account. The central account has one destination in us-east-1 and one in eu-west-1, and both target an Amazon Kinesis Data Streams data stream in us-east-1. A new data residency rule requires the stream that stores the audit events to move to eu-central-1. The log groups stay where they are. Which solution will meet these requirements?

    Right. In the game that’s Renown for your Monitoring and Logging building.

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

    Show the full explanation and doc quotes

    So the two existing destinations stay in us-east-1 and eu-west-1, and only what they point at changes. PutDestination both creates and updates a destination, so the central account updates each one with the new stream in eu-central-1 as its target, and gives the role that the destinations pass to CloudWatch Logs permission to put records into that stream. The destination ARNs do not change, so the subscription filters in the 30 accounts keep working untouched.

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

Ask for something