考题解析 | 在 AWS 中将 Lambda 函数日志发送到 CloudWatch Logs


  题目

A company is developing a new serverless application that uses AWS Lambda functions. The company uses AWS CloudFormation to deploy the Lambda functions. The company’s developers are trying to debug a Lambda function that is deployed. The developers cannot debug the Lambda function because the Lambda function is not logging its output to Amazon CloudWatch Logs.
Which combination of steps should a security engineer take to resolve this issue? (Choose two.)
A. Check the role that is defined in the CloudFormation template and is passed to the Lambda function. Ensure that the role has a trust policy that allows the sts:AssumeRole action by the service principal lambda amazonaws.com.
B. Check the execution role that is configured in the CloudFormation template for the Lambda function. Ensure that the execution role has the necessary permissions to write to CloudWatch Logs.
C. Check the Lambda function configuration in the CloudFormation template. Ensure that the Lambda function has an AWS X-Ray tracing configuration that is set to Active mode or PassThrough mode.
D. Check the resource policy that is configured in the CloudFormation template for the Lambda function. Ensure that the resource policy has the necessary permissions to write to CloudWatch Logs.
E. Check the role that the developers use to debug the Lambda function. Ensure that the role has a trust policy that allows the sts:AssumeRole action by the service principal lambda.amazonaws.com.

  参考答案

AB

  需求概括

一家公司正在开发一个使用AWS Lambda函数的新型无服务器应用程序。该公司使用AWS CloudFormation来部署Lambda函数。该公司的开发人员正在尝试调试一个已部署的Lambda函数,但无法进行调试,因为该Lambda函数未将其输出记录到Amazon CloudWatch Logs中。安全工程师应采取哪两个步骤组合来解决此问题?
该公司使用AWS CloudFormation部署的Lambda函数无法将输出记录到CloudWatch Logs,导致开发人员无法调试,需要安全工程师找出解决该问题的两个步骤组合。

  技术分析

要使Lambda函数能够将输出记录到CloudWatch Logs,需要确保Lambda函数有足够的权限来执行此操作。这涉及到检查与Lambda函数相关的各种角色和策略,看它们是否具备写入CloudWatch Logs的必要权限。具体来说,需要关注Lambda函数的执行角色以及可能涉及的其他角色和策略,因为执行角色决定了Lambda函数在运行时可以执行的操作。

  参考解析

技巧:排除明显错误选项,在没有明显错误的选项中选择最合理的选项。

A. 正确。检查在CloudFormation模板中定义并传递给Lambda函数的角色。确保该角色具有允许服务主体lambda.amazonaws.com执行sts:AssumeRole操作的信任策略。该选项关注的是角色的信任策略,主要涉及角色能否被特定服务主体承担。这是
B. 正确。检查在CloudFormation模板中为Lambda函数配置的执行角色。确保执行角色具有写入CloudWatch Logs的必要权限。该选项是解决该问题的关键步骤之一。因为Lambda函数的执行角色决定了它在运行时可以执行的操作,如果执行角色没有写入CloudWatch Logs的权限,Lambda函数就无法将输出记录到其中。所以该选项正确。
C. 不正确。检查CloudFormation模板中的Lambda函数配置。确保Lambda函数具有设置为Active模式或PassThrough模式的AWS X-Ray跟踪配置。AWS X-Ray跟踪配置主要用于应用程序的性能分析和跟踪,与Lambda函数能否将输出记录到CloudWatch Logs无关。
D. 不正确。检查在CloudFormation模板中为Lambda函数配置的资源策略。确保资源策略具有写入CloudWatch Logs的必要权限。资源策略主要用于控制对Lambda函数资源的访问,而不是决定Lambda函数自身能否写入CloudWatch Logs,写入权限主要由执行角色决定。
E. 不正确。检查开发人员用于调试Lambda函数的角色。确保该角色具有允许服务主体lambda.amazonaws.com执行sts:AssumeRole操作的信任策略。该选项关注的是开发人员调试用的角色的信任策略,与Lambda函数能否将输出记录到CloudWatch Logs没有直接关系。