feat(logs): set custom log group name for API Gateway logs by eahefnawy · Pull Request #13283 · serverless/serverless
📝 Walkthrough
Walkthrough
Adds a configurable logGroup string for REST API, HTTP API, and WebSocket API logging under provider.logs.*, updates provider schema, compilation logic to honor the custom names, and documents the new options and examples.
Changes
| Cohort / File(s) | Summary |
|---|---|
Documentation docs/sf/providers/aws/events/apigateway.md, docs/sf/providers/aws/events/http-api.md, docs/sf/providers/aws/events/websocket.md, docs/sf/providers/aws/guide/serverless.yml.md |
Added examples and guidance for provider.logs.restApi.logGroup, provider.logs.httpApi.logGroup, and provider.logs.websocket.logGroup; documented default CloudWatch paths and override behavior. |
REST API compilation packages/serverless/lib/plugins/aws/package/compile/events/api-gateway/lib/hack/update-stage.js, packages/serverless/lib/plugins/aws/package/compile/events/api-gateway/lib/stage.js |
Use logs.logGroup when present for computed logGroupName; fall back to /aws/api-gateway/${service}-${stage}; updated getLogGroupResource signature to accept logs. |
HTTP API compilation packages/serverless/lib/plugins/aws/package/compile/events/http-api.js |
Propagate logs.logGroup into compilation config (this.config.logGroup) and derive LogGroupName from it when provided; otherwise use default HTTP API naming. |
WebSocket compilation packages/serverless/lib/plugins/aws/package/compile/events/websockets/lib/stage.js |
Accept logs in getLogGroupResource, compute logGroupName from logs.logGroup or default /aws/websocket/${service}-${stage}, and pass logs at call sites. |
Provider schema packages/serverless/lib/plugins/aws/provider.js |
Added logGroup: { type: 'string' } to logs.restApi, logs.httpApi, and logs.websocket schema definitions to validate custom log group names. |
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~22 minutes
Poem
🐰 I found a log path bright and new,
/aws or /my-custom—your choice rings true,
REST, HTTP, WebSocket in a row,
I hop, I document, I let them know,
CloudWatch gardens now bloom with your view.
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
✅ Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title accurately describes the main change: adding support for custom log group names for API Gateway logs across REST API, HTTP API, and WebSocket. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing touches
- 📝 Generate docstrings
Comment @coderabbitai help to get the list of available commands and usage tips.