amazon-web-services - 为无服务器 websocket 应用禁用 Cloudwatch 日志
问题描述
我有一个使用无服务器框架在 AWS 上托管的 WebSocket API。
问题是我每分钟看到 15 万条日志,而且成本很高。
以下日志组是问题所在:
- /aws/apigateway/mzl9lpgzn0/production
- API-Gateway-Execution-Logs_xkkvpjzgqj/production
我已经按照他们的文档禁用了这样的日志,但它显示了一个错误。
service: BotBindSocketAPI
custom:
customDomain:
- domainName: ${ssm:/botapi/${opt:stage}/wsName}
stage: ${opt:stage}
websocket: true
provider:
name: aws
runtime: nodejs10.x
stage: ${opt:stage}
region: us-east-1
logRetentionInDays: 7
logs:
restApi:
accessLogging: false
executionLogging: false
level: ERROR
fullExecutionData: true
websocket: false
frameworkLambda: false
iamRoleStatements:
- Effect: Allow
Action:
- "execute-api:ManageConnections"
Resource:
- "arn:aws:execute-api:*:*:**/@connections/*"
- Effect: Allow
Action:
- "s3:GetObject"
- "s3:PutObject"
Resource:
- "arn:aws:s3:::botbind-addons/*"
vpc:
truncated
functions:
websocketHandler:
handler: handler.websocketHandler
events:
- websocket:
route: $connect
authorizer: authHandler
- websocket:
route: $disconnect
- websocket:
route: $default
- websocket:
route: ping
- websocket:
route: getBot
authHandler:
handler: handler.authHandler
plugins:
- serverless-offline
- serverless-domain-manager
错误:
Serverless Error ---------------------------------------
An error occurred: WebsocketsDeploymentStage - The following context variables are not supported: [$context.status] (Service: AmazonApiGatewayV2; Status Code: 400; Error Code: BadRequestException; Request ID: 4a522b6c-6ade-4f86-afcf-35017a22c30c).
这是禁用 API 日志的正确方法,因此我可以降低 CloudWatch 成本吗?
解决方案
对于无服务器框架,您将需要这样的东西:
functions:
myCloudWatchLog:
handler: myCloudWatchLog.handler
events:
- cloudwatchLog:
logGroup: '/aws/lambda/hello'
filter: '{$.userIdentity.type = Root}'
来源https://serverless.com/framework/docs/providers/aws/events/cloudwatch-log/
推荐阅读
- javascript - 将 API 中的 JSON 数据保存到数据库中并缓存请求,因此我不需要再次从 API 请求 - Node.js / Express.js
- c# - 我有 ac# 一个控制台应用程序,我需要将其转换为 Azure 函数
- python - 在 Pyspark 上运行 K-Means
- scala - 如何将尾递归方法转换为更类似于 Scala 的函数?
- r - Data.Table 列的非零值
- ruby-on-rails - 来自对 Rails 主动存储 API 做出反应的“未经许可的参数”
- html - 使用 div 元素使我的按钮居中
- certificate - Quarkus - 使用 Postman 查询受 TLS/SSL 保护的资源
- python - 使用基于时间的分桶快速将数据帧保存到 mongodb?
- qt-creator - 更改 Qt Creator 界面缩放/字体大小