This is an automated email from the ASF dual-hosted git repository.

membphis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 9fc501f03 fix(aws-lambda): request "/" for a path-less function_uri 
and log function error responses (#13908)
9fc501f03 is described below

commit 9fc501f03aa72d12a8b73e0ddf8a8e50afca4880
Author: Mohammad Izzraff Janius 
<[email protected]>
AuthorDate: Wed Sep 2 17:21:54 2026 +0900

    fix(aws-lambda): request "/" for a path-less function_uri and log function 
error responses (#13908)
    
    Fixes #11176
---
 apisix/plugins/serverless/generic-upstream.lua |  10 ++-
 t/plugin/aws-lambda.t                          | 100 +++++++++++++++++++++++++
 2 files changed, 109 insertions(+), 1 deletion(-)

diff --git a/apisix/plugins/serverless/generic-upstream.lua 
b/apisix/plugins/serverless/generic-upstream.lua
index 4caa35c78..2e9ab94c0 100644
--- a/apisix/plugins/serverless/generic-upstream.lua
+++ b/apisix/plugins/serverless/generic-upstream.lua
@@ -83,7 +83,10 @@ return function(plugin_name, version, priority, 
request_processor, authz_schema,
 
         -- forward the url path came through the matched uri
         local url_decoded = url.parse(conf.function_uri)
-        local path = url_decoded.path or "/"
+        local path = url_decoded.path
+        if path == "" then
+            path = "/"
+        end
 
         if ctx.curr_req_matched and ctx.curr_req_matched[":ext"] then
             local end_path = ctx.curr_req_matched[":ext"]
@@ -127,6 +130,11 @@ return function(plugin_name, version, priority, 
request_processor, authz_schema,
             return 503
         end
 
+        if res.status >= 400 then
+            core.log.warn(plugin_name, " function returned status ", 
res.status,
+                          ", body: ", res.body)
+        end
+
         -- According to RFC7540 
https://datatracker.ietf.org/doc/html/rfc7540#section-8.1.2.2,
         -- endpoint must not generate any connection specific headers for 
HTTP/2 requests.
         local response_headers = res.headers
diff --git a/t/plugin/aws-lambda.t b/t/plugin/aws-lambda.t
index e79e43715..603d06478 100644
--- a/t/plugin/aws-lambda.t
+++ b/t/plugin/aws-lambda.t
@@ -46,6 +46,12 @@ add_block_preprocessor(sub {
                 $inside_lua_block
             }
         }
+
+        location = / {
+            content_by_lua_block {
+                ngx.say("request_uri: ", ngx.var.request_uri)
+            }
+        }
     }
 _EOC_
 
@@ -582,3 +588,97 @@ passed
     }
 --- response_body
 PASS
+
+
+
+=== TEST 12: function_uri without a path is requested as "/"
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+
+            local code, body = t('/apisix/admin/routes/1',
+                 ngx.HTTP_PUT,
+                 [[{
+                        "plugins": {
+                            "aws-lambda": {
+                                "function_uri": "http://localhost:8765";,
+                                "authorization": {
+                                    "iam": {
+                                        "accesskey": "KEY1",
+                                        "secretkey": "KeySecret"
+                                    }
+                                }
+                            }
+                        },
+                        "uri": "/aws"
+                }]]
+            )
+            if code >= 300 then
+                ngx.status = code
+                ngx.say("fail")
+                return
+            end
+
+            ngx.say(body)
+
+            local code, _, body = t("/aws", "GET")
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.print(body)
+        }
+    }
+--- response_body
+passed
+request_uri: /
+
+
+
+=== TEST 13: function error status and body are forwarded and logged
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+
+            local code, body = t('/apisix/admin/routes/1',
+                 ngx.HTTP_PUT,
+                 [[{
+                        "plugins": {
+                            "aws-lambda": {
+                                "function_uri": 
"http://localhost:8765/generic";,
+                                "authorization": {
+                                    "iam": {
+                                        "accesskey": "KEY1",
+                                        "secretkey": "KeySecret"
+                                    }
+                                }
+                            }
+                        },
+                        "uri": "/aws"
+                }]]
+            )
+            if code >= 300 then
+                ngx.status = code
+                ngx.say("fail")
+                return
+            end
+
+            ngx.say(body)
+
+            local code, body = t("/aws", "GET")
+            ngx.say("status: ", code)
+            ngx.print(body)
+        }
+    }
+--- inside_lua_block
+ngx.status = 403
+ngx.say([[{"message":"The security token included in the request is 
invalid."}]])
+--- response_body
+passed
+status: 403
+{"message":"The security token included in the request is invalid."}
+--- error_log
+aws-lambda function returned status 403, body: {"message":"The security token 
included in the request is invalid."}
+--- no_error_log
+[error]

Reply via email to