我尝试通过 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/