【问题标题】:Serverless API Gateway Logging无服务器 API 网关日志记录
【发布时间】:2021-01-03 07:24:42
【问题描述】:

对于任何可以提供帮助的人,

我正在尝试让无服务器 aws API 网关日志正常工作,但没有任何乐趣,我有多个端点,当我部署代码时,会在 cloudwatch 中为每个端点创建日志组,但在查询时不会创建日志或日志流端点。下面的代码用于定义日志记录的一个端点。

我注意到在 aws api 网关的阶段下 -> 日志/跟踪没有点击启用 cloudwatch 日志。当我手动单击此按钮时,日志记录会起作用,但会记录到通用的 cloudwatch 日志组。

provider:
  name: aws
  runtime: nodejs12.x
  region: us-west-1
  apiGateway:
    restApiId:
      “Fn::ImportValue”: SharedGW-restApiId
    restApiRootResourceId:
      “Fn::ImportValue”: SharedGW-rootResourceId
  logs:
    restApi:
      accessLogging: true
      format: ‘requestId: $context.requestId’
      executionLogging: true
      role: arn:aws:iam::1234567890:role/Test-Logs-Gateway
      roleManagedExternally: true
      level: INFO
      fullExecutionData: true

【问题讨论】:

    标签: serverless-framework aws-serverless


    【解决方案1】:

    您似乎正在导入 API 网关,您应该在创建 api 网关的位置添加该配置。

    【讨论】:

    • 如果 API 网关已经存在或正在使用其他工具(如 Terraform)构建怎么办?
    • 你需要在源头更新,serverless使用cloudformation,如果我没记错的话,因为没有创建资源,所以无法更新。
    • 在我们的例子中,我们使用 Terraform 创建 API,并且能够使用无服务器添加方法和端点。我们还可以更改文档等。但是当 API 不是由 serverless/CloudFormation 创建时,似乎只支持日志记录。
    • 为什么不考虑使用开放 api 规范而不是无服务器部署?
    猜你喜欢
    • 1970-01-01
    • 2014-07-21
    • 1970-01-01
    • 2016-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多