AWS Lambda 目标 Lambda 未触发

AWS Lambda destination Lambda not triggering

背景:

我正在通过 Terraform 开发自定义 AWS github-webhook。我正在使用 AWS API 网关触发 AWS Lambda 函数,该函数从请求 header 中验证 GitHub webhook 的 sha256 签名。如果 lambda 函数成功验证请求,我希望通过 Lambda 提供的异步调用目标功能调用 child lambda 函数。

问题:

尽管我已经使用目标 child Lambda 函数配置了异步调用,但当 parent Lambda 函数成功时,child 函数不会被触发。这反映在 child Lambda 函数的关联 CloudWatch 日志组为空这一事实中。

相关代码:

这是 Lambda 函数目标的 Terraform 配置:

resource "aws_lambda_function_event_invoke_config" "lambda" {
  function_name = module.github_webhook.function_name
  destination_config {
    on_success {
      destination = module.lambda.function_arn
    }
  }
}

如果需要模块中的更多代码,请随时在评论中提问。此模块的完整源代码在这里:https://github.com/marshall7m/terraform-aws-codebuild/tree/master/modules/dynamic-github-source

尝试次数:

根据您的描述,我认为您是在同步调用父函数。 Lambda destinations 仅适用于 异步 调用:

You can also configure Lambda to send an invocation record to another service. Lambda supports the following destinations for asynchronous invocation

因此您必须异步执行父函数才能调用子函数。

添加 API 集成请求参数 `{'X-Amz-Invocation-Type': 'Event'} 中提到的:https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-integration-async.html 成功了。我最初得出的结论是该解决方案不起作用,因为在我重新交付 github 负载时未创建新的 Cloudwatch 日志组流。事实证明,当我仔细查看之前的 Cloudwatch 日志流时,我发现 Cloudwatch 将重新触发的 Lambda 函数调用的日志附加到之前关联的 Cloudwatch 日志流。