为无服务器 websocket 应用程序禁用 Cloudwatch 日志
Disable Cloudwatch logs for serverless websocket app
我有一个 WebSocket API 使用无服务器框架托管在 AWS 上。
问题是我每分钟看到 150k 条日志,而且要花很多钱。
以下日志组是问题所在:
- /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/
我有一个 WebSocket API 使用无服务器框架托管在 AWS 上。
问题是我每分钟看到 150k 条日志,而且要花很多钱。
以下日志组是问题所在:
- /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/