我想为我的 api 网关启用 api 网关日志,这是我的 lambda 函数的封装。
service: myservice
provider:
name: aws
runtime: python3.6
stage: ${opt:stage}
region: ${self:custom.AwsRegion}
timeout: 130
memorySize: 128
functions:
create_user:
handler: functions/create_user.lambda_handler
events:
- http:
path: /create_user
method: post
authorizer: aws_iam
private: true
当我部署这个时,我确实在云 watch 中看到了 lambda 日志。但 API 网关日志并未在 cloudwatch 中重新编码。任何人都可以启发我有关云形成语法的知识,以便为我的 api 网关启用日志吗?
我尝试添加以下代码,但看起来它正在尝试创建新的 api 端点。
资源: 资源:
ApiGatewayStage:
Type: AWS::ApiGateway::Stage
Properties:
RestApiId:
Ref: ApiGatewayRestApi
StageName: ${opt:stage}
MethodSettings:
- DataTraceEnabled: true
HttpMethod: "*"
LoggingLevel: INFO
ResourcePath: "/*"
MetricsEnabled: true
最佳答案
您可以通过外部插件来完成此操作,此处详细讨论了解决方案。
关于lambda - 如何通过cloudformation模板(serverless.yml)启用api网关日志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46371287/