我可以将 CloudWatch 日志组从另一个账户流式传输到 lambda 吗?

Can I stream CloudWatch log group to lambda from another account?

我可以将 CloudWatch 日志组从另一个账户流式传输到 lambda 吗?我尝试从 AWS 控制台配置它,但它只显示当前账户的 lambda。

提示:我对 Amazon Kinesis 解决方案不感兴趣。我知道如何通过这里描述的订阅来做到这一点:http://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CrossAccountSubscriptions.html

我正在从另一个帐户准确询问 lambda。

P.S。我试图从另一个帐户向 lambda 添加对日志组的订阅,正如所描述的那样 here,但我收到了以下错误:

An error occurred (AccessDeniedException) when calling the PutSubscriptionFilter
operation: Cross-account lambda invocation passing is not allowed. You must use DestinationPolicies to create cross account lambda triggers.

目前没有。这包括使用 CloudWatch Logs Destination

此处更详细地记录了 PutSubscriptionFilter 的限制:https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_PutSubscriptionFilter.html

CloudWatch Logs 仅支持将日志数据流式传输到同一账户中的 Lambda 函数,尽管不明确的错误消息似乎表明它 可能 是可能的。

我怀疑错误信息:

You must use DestinationPolicies to create cross account lambda triggers.

对于任何尝试 cross-account lambda 调用的服务来说都是通用的,并且对于像 SNS 这样的服务来说是有意义的,您可以在其中向主题添加权限以允许它。

或者,您可能想使用 CloudWatch 日志目标发送到 Lambda 函数,但是,目标仅支持 Kinesis。

最近的 AWS 记录在此处:https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_PutDestination.html

关于目标 ARN 的说明如下:

The ARN of an Amazon Kinesis stream to which to deliver matching log events.

尽管如此,如果仍然有可能,我尝试遵循这些 instructions,用 Lambda 函数替换 Kinesis 流,但在最后一步遇到了这个错误,我是'能够解决。

$ aws logs put-destination --destination-name "testDestination" --target-arn "arn:aws:lambda:us-east-1:<YOUR ACCOUNT ID HERE>:function:destinationtest" --role-arn "arn:aws:iam::<YOUR ACCOUNT ID HERE>:role/CWLtoLambdaRole"

An error occurred (InvalidParameterException) when calling the PutDestination operation: Could not deliver test message to specified destination. Check if the destination is valid.

综上所述,我不得不得出结论,答案仍然是否定的,无法跨账户直接将 Lambda 函数连接到 CloudWatch 日志。但是,您可以在单独的账户中使用 Kinesis 流作为目标,然后您可以非常轻松地订阅 Lambda 函数。

现在好像可以了?

来自文档:

destinationArn
The ARN of the destination to deliver matching log events to. Currently, the supported destinations are:

A logical destination (specified using an ARN) belonging to a different account, for cross-account delivery.