【问题标题】:How can I log lambda request id into AWS CloudWatch Api gateway log group with JSON format?如何使用 JSON 格式将 lambda 请求 ID 记录到 AWS CloudWatch Api 网关日志组中?
【发布时间】:2019-06-30 18:48:09
【问题描述】:

我一直在研究使用 AWS API Gateway 和 lambda 函数的 REST API。 Api 网关和 lambda 服务都在记录到 CloudWatch 服务。我需要将 lambda 请求 ID 记录到 AWS CloudWatch API 网关日志组中。 (API-Gateway-Execution-Logs_{api_id}/{staging})。

我设法以文本格式获取 lambda 请求 ID,但我想以 JSON 格式记录它。在 API 网关日志中,它被标记为“AWS Integration Endpoint RequestId”。 我试图从以下链接中找到此属性: List of Log Variables

目前,“$context.requestId”已添加到我的 CloudWatch 日志中。这是 API Gateway 的请求 ID。我需要 API Gateway 日志中的 lambda 请求 ID。 我试图记录“$context.authorizer.principalId”,但它是空的。

如何从 API 网关请求的上下文对象中获取 lambda 请求 ID?

【问题讨论】:

    标签: amazon-web-services aws-api-gateway amazon-cloudwatchlogs


    【解决方案1】:

    APIG reference看来,你可以使用$context.awsEndpointRequestId占位符

    【讨论】:

      猜你喜欢
      • 2019-10-26
      • 2019-09-06
      • 2020-05-13
      • 2021-05-16
      • 2017-07-05
      • 2020-05-27
      • 1970-01-01
      • 1970-01-01
      • 2018-02-16
      相关资源
      最近更新 更多