如何通过 Cloudformation 模板为 AWS API GW 启用 Cloudwatch 日志记录

Ath*_*thi 12 amazon-web-services aws-cloudformation aws-api-gateway api-gateway

我尝试通过 cloudformation 模板为 AWS API Gateway 启用 cloudwatch 日志,但它没有启用。我尝试在阶段描述和方法设置中将日志记录级别设置为 INFO。你知道我错过了什么吗?

当我通过 UI 手动启用日志记录时,它可以工作。当我尝试通过 cloudformation 模板启用时不起作用,如下所示 -

注意:我只是使用普通的 cloudformation 模板,并且我已经添加了角色 ARN,该角色 ARN 有权在我的帐户中访问 API Gateway 来记录 cloudwatch

TestDeployment:
  Type: AWS::ApiGateway::Deployment
  Properties:
    Description: API Deployment
    RestApiId: testApi
    StageName: 'dev'
    StageDescription:
      Description: Stage - DEV
      LoggingLevel: INFO
      MethodSettings:
        - ResourcePath: "/testresource"
          HttpMethod: "POST"
          LoggingLevel: INFO
Run Code Online (Sandbox Code Playgroud)

Nic*_*coM 1

您是否已配置 API Gateway RestApi 以将日志写入 CloudWatch,如 AWS 文档中所述: https: //docs.aws.amazon.com/apigateway/latest/developerguide/set-up-logging.html

请注意,您必须设置 CloudWatch 日志记录的权限。