使用 cloudformation 在 API Gateway V2 阶段启用 CloudWatch 日志

Enable CloudWatch logs in API GatewayV2 Stage with cloud formation

有一个但它没有使用AWS::ApiGatewayV2::Stage,我需要AutoDeploy,似乎只有V2提供。

如何在 AWS API 网关中使用 CloudFormation 启用 CloudWatch 日志并记录完整的消息数据(如图所示)?

我在舞台文档中找不到任何内容 https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-stage.html#cfn-apigatewayv2-stage-deploymentid

我正在使用自动部署阶段。我能够创建日志组,IAM 角色在 CloudWatch 中写入日志,但我无法启用日志记录本身。

wsApiGateway:
  Type: AWS::ApiGatewayV2::Api
  Properties:
    Name: foo-ws-gateway
    Description: Api Gateway for Websockets
    ProtocolType: WEBSOCKET
    RouteSelectionExpression: $request.body.action
    DisableExecuteApiEndpoint: true # I use custom domain

# routes and integrations ommitted.

wsApiStage:
  Type: AWS::ApiGatewayV2::Stage
  DependsOn:
    - wsConnectRoute
    - wsSendRoute
    - wsDisconnectRoute
  Properties:
    StageName: production
    Description: Autodeploy in production
    AutoDeploy: true
    ApiId: !Ref wsApiGateway
    AccessLogSettings:
      DestinationArn: !GetAtt wsApiGatewayLogGroup.Arn
      Format: '{"requestTime":"$context.requestTime","requestId":"$context.requestId","httpMethod":"$context.httpMethod","path":"$context.path","routeKey":"$context.routeKey","status":$context.status,"responseLatency":$context.responseLatency, "responseLength":$context.responseLength, "integrationError":$context.integration.error}'

我还必须转到 ApiGateway 以前的版本来定义帐户,以便我可以指定 IAM 角色 ARN,该角色 ARN 对帐户中的 CloudWatch 日志具有写入权限(关于设置的部分位于控制台的 API 网关)。它似乎没有 AWS::ApiGateway2::Account.

apiGatewayAccountConfig:
  Type: "AWS::ApiGateway::Account"
  Properties:
    CloudWatchRoleArn: !GetAtt apiGatewayWatchLogsRole.Arn

How do I enable CloudWatch logs and log full message data (as per the image) using CloudFormation in an AWS API Gateway?

你不能。 HTTP API(即 ApiGatewayV2)不支持 执行日志,如 AWS here:

所解释

HTTP APIs currently support access logging only, and logging setup is different for these APIs. For more information, see Configuring logging for an HTTP API.