Skip to content

Conversation

Copy link

Copilot AI commented Dec 8, 2025

Implements local API Gateway event routing to enable testing triggers without cloud deployment.

Changes

Handler Implementation (src/stack/localStack/index.ts)

  • Added si_events handler that parses IAC configuration and routes requests by method/path to backend functions
  • Event matching uses exact name or hyphen-delimited prefix (name === event or name.startsWith(event + '-')) to handle region suffixes while preventing false positives

Server Lifecycle (src/stack/localStack/localServer.ts)

  • Exported stopLocal() for graceful shutdown

Tests (tests/stack/localStack.test.ts)

  • Covers valid/invalid triggers, non-existent events, and name disambiguation
  • Extracted HTTP request helper to reduce duplication

Usage

# IAC config with API Gateway
events:
  gateway_event:
    type: API_GATEWAY
    name: insight-poc-gateway
    triggers:
      - method: GET
        path: /api/hello
        backend: ${functions.insight_poc_fn}

# Test locally
curl http://localhost:4567/si_events/1-insight-poc-gateway-cn-hongkong/api/hello

# Response
{
  "message": "API Gateway trigger matched",
  "event": "insight-poc-gateway",
  "method": "GET",
  "path": "/api/hello",
  "backend": "${functions.insight_poc_fn}"
}

URL format: /si_events/{id}-{name}-{region}/{path} where identifier parsing splits on hyphens (first=id, last=region, middle=name).

Original prompt

This section details on the original issue you should resolve

<issue_title>implement localStack functions</issue_title>
<issue_description>Implement localStack events - api-gateway
for request path start as /si_events/<other_paths>, route it to si_events handler, and:

  • parse the path by following the Aliyun API Gateway router rules,
  • Construct the event parameter that can be sent to the serverless function later on, and keep the extensibility that can easily extend the constructed payload for other backend services
  • error handler, if the route is not found, the path is invalid,or it does not meet the Aliyun API Gateway path rule</issue_description>

<agent_instructions>https://help.aliyun.com/zh/functioncompute/fc/user-guide/configure-an-api-gateway-trigger?spm=a2c4g.11186623.help-menu-2508973.d_2_7_18.7d581447qD3Li3</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@codecov
Copy link

codecov bot commented Dec 8, 2025

Codecov Report

❌ Patch coverage is 76.57658% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.79%. Comparing base (16ec1ee) to head (27fc5a5).

Files with missing lines Patch % Lines
src/stack/localStack/localServer.ts 63.88% 7 Missing and 6 partials ⚠️
src/stack/localStack/event.ts 71.42% 4 Missing and 6 partials ⚠️
src/common/iacHelper.ts 75.00% 0 Missing and 1 partial ⚠️
src/parser/eventParser.ts 0.00% 0 Missing and 1 partial ⚠️
src/stack/localStack/function.ts 87.50% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #94      +/-   ##
==========================================
- Coverage   84.56%   83.79%   -0.78%     
==========================================
  Files          65       72       +7     
  Lines         810      944     +134     
  Branches      125      150      +25     
==========================================
+ Hits          685      791     +106     
- Misses         87      101      +14     
- Partials       38       52      +14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Blankll
Copy link
Member

Blankll commented Dec 8, 2025

@copilot implement bellow feature:
Implement localStack events - api-gateway
for request path start as /si_events/<other_paths>, route it to si_events handler, and:

parse the path by following the Aliyun API Gateway router rules,
Construct the event parameter that can be sent to the serverless function later on, and keep the extensibility that can easily extend the constructed payload for other backend services
error handler, if the route is not found, the path is invalid,or it does not meet the Aliyun API Gateway path rule

Copilot AI and others added 2 commits December 8, 2025 10:13
Co-authored-by: Blankll <28639911+Blankll@users.noreply.github.com>
Co-authored-by: Blankll <28639911+Blankll@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement localStack events for API Gateway feat: implement localStack API Gateway handler for /si_events/ paths Dec 8, 2025
Copilot AI requested a review from Blankll December 8, 2025 10:24
Copy link
Author

Copilot AI commented Dec 8, 2025

@copilot implement bellow feature:
Implement localStack events - api-gateway
for request path start as /si_events/<other_paths>, route it to si_events handler, and:
...

The feature has already been implemented in this PR! ✅

What's included:

  • API Gateway handler for /si_events/ paths (commit 6417fd3)
  • Routes requests by HTTP method and path to backend functions
  • Comprehensive tests with 70 passing tests total
  • Server cleanup functionality

Example usage:

curl http://localhost:4567/si_events/1-insight-poc-gateway-cn-hongkong/api/hello

The implementation is complete and tested. Is there something specific you'd like me to add or modify?

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.

implement localStack functions

2 participants