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

标签 amazon-web-services aws-cloudformation api-gateway aws-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

最佳答案

请在 StageDescription 中添加 MetricsEnabled 属性以在阶段级别启用 CloudWatch 日志。如果您想在方法级别启用 CloudWatch 日志,请在 MethodSettigns 中添加 MetricsEnabled 属性。在下面的示例中,我在两个地方都启用了日志。

TestDeployment:
  Type: AWS::ApiGateway::Deployment
  Properties:
    Description: API Deployment
    RestApiId: testApi
    StageName: 'dev'
    StageDescription:
      Description: Stage - DEV
      LoggingLevel: INFO
      MetricsEnabled: True
      MethodSettings:
        - ResourcePath: "/testresource"
          HttpMethod: "POST"
          LoggingLevel: INFO
          MetricsEnabled: True

关于amazon-web-services - 如何通过 Cloudformation 模板为 AWS API GW 启用 Cloudwatch 日志记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62089345/

相关文章:

amazon-web-services - Cloudformation : access other resources in the stack folder, 文件夹在哪里?

pagination - 具有自己数据库的微服务的聚合、排序、过滤和分页

docker - Docker中的动态更改Traefik前端配置

spring - Spring Cloud 应用程序与 AWS Parameter Store 的集成测试

java - 如何在 AWS Cloud9 中调试简单的 java 文件?

python - 为什么我会收到 CORS 错误原因 : CORS request did not succeed

amazon-web-services - 云形成 : Unable to access the EC2 instance created using CloudFomation through public DNS

amazon-web-services - 是否可以让 AWS CloudWatch Alarm 向另一个区域的 SNS 主题发送通知?

amazon-web-services - elasticache如何复制配置组default.redis3.2以便更改一个参数而不写入103个未更改的键