Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(logs): set custom log group name for API Gateway logs#13283

Draft
eahefnawy wants to merge 2 commits intomainfrom
custom-apig-log-group-name
Draft

feat(logs): set custom log group name for API Gateway logs#13283
eahefnawy wants to merge 2 commits intomainfrom
custom-apig-log-group-name

Conversation

@eahefnawy
Copy link
Contributor

@eahefnawy eahefnawy commented Jan 20, 2026

Adds support for custom CloudWatch log group names for API Gateway access logs via provider.logs.{restApi|httpApi|websocket}.logGroup, matching the existing pattern for Lambda logs (provider.logs.lambda.logGroup).

Usage

provider:
  logs:
    restApi:
      logGroup: /custom/rest-api
    httpApi:
      logGroup: /custom/http-api
    websocket:
      logGroup: /custom/websocket

Changes

  • Added logGroup property to schema for restApi, httpApi, and websocket logs
  • Updated stage compilation to use custom log group names (with existing defaults as fallback)
  • Updated documentation (apigateway.md, http-api.md, websocket.md, serverless.yml.md)

Summary by CodeRabbit

  • New Features

    • Added a provider-level logGroup option to customize CloudWatch log group names for REST API, HTTP API, and WebSocket API logging.
  • Documentation

    • Updated docs with examples showing how to set provider.logs.{restApi,httpApi,websocket}.logGroup and a note that provider log settings are ignored when an external REST API resource is used.

✏️ Tip: You can customize this high-level summary in your review settings.

@eahefnawy eahefnawy requested a review from czubocha January 20, 2026 19:06
@Mmarzex
Copy link
Contributor

Mmarzex commented Jan 20, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 20, 2026

📝 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/serverless/lib/plugins/aws/package/compile/events/api-gateway/lib/hack/update-stage.js (1)

405-423: Avoid deleting user-managed custom log groups.

With logs.logGroup now supported, disabling accessLogging can delete a user-provided log group that may be shared or managed outside this stack. That’s a data‑loss risk; deletion should be limited to the default log group (or gated by an explicit opt‑in).

💡 Suggested safeguard
   const logs = provider.logs && provider.logs.restApi
-  const logGroupName =
-    (logs && logs.logGroup) || `/aws/api-gateway/${service}-${stage}`
+  const hasCustomLogGroup = Boolean(logs && logs.logGroup)
+  const logGroupName =
+    (logs && logs.logGroup) || `/aws/api-gateway/${service}-${stage}`

   let accessLogging = logs

   if (accessLogging) {
     accessLogging =
       accessLogging.accessLogging == null ? true : accessLogging.accessLogging
   }

   // if there are no logs setup (or the user has disabled them) we need to
   // ensure that the log group is removed. Otherwise we'll run into duplicate
   // log group name issues when logs are enabled again
   if (!accessLogging) {
+    if (hasCustomLogGroup) return Promise.resolve()
     return this.provider
       .request('CloudWatchLogs', 'deleteLogGroup', {
         logGroupName,
       })

@czubocha czubocha marked this pull request as draft January 29, 2026 10:38
@czubocha czubocha removed their request for review January 30, 2026 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants