janiussyafiq opened a new pull request, #13908:
URL: https://github.com/apache/apisix/pull/13908

   ### Description
   
   `aws-lambda` (and the other plugins built on 
`serverless/generic-upstream.lua`: `azure-functions`, `openfunction`) answered 
`400 Bad Request` with no useful detail when `function_uri` had no path, e.g. 
`https://xxx.lambda-url.us-east-1.on.aws` without the trailing slash. `net.url` 
parses that into an empty path string, and `url_decoded.path or "/"` never 
kicked in because `""` is truthy in Lua. The plugin then sent `GET  HTTP/1.1` 
with an empty request-target, which the function host rejects before it reaches 
the function. This is the "wrong URL" case from the issue.
   
   The issue also asks for better troubleshooting output on wrong IAM 
credentials. The function's error body (for example AWS's `The security token 
included in the request is invalid.`) was already forwarded to the client, but 
`error.log` only carried `aws-lambda exits with http status code 403`, so an 
operator looking at the gateway alone could not tell why.
   
   Changes:
   
   - Treat an empty parsed path as `/`, so the request-target matches the SigV4 
canonical URI and is accepted by the function host.
   - When the function answers with a 4xx/5xx, log the status and body at 
`warn` level (same shape as `authz-keycloak`), in addition to forwarding them 
to the client unchanged.
   
   Tests: `t/plugin/aws-lambda.t` TEST 10 (a path-less `function_uri` reaches 
the mock as `/`) and TEST 11 (a 403 JSON body is forwarded to the client and 
present in `error.log`). Both fail without the fix.
   
   #### Which issue(s) this PR fixes:
   Fixes #11176
   
   ### Checklist
   
   - [x] I have explained the need for this PR and the problem it solves
   - [x] I have explained the changes or the new features added to this PR
   - [x] I have added tests corresponding to this change
   - [ ] I have updated the documentation to reflect this change
   - [x] I have verified that this change is backward compatible (If not, 
please discuss on the [APISIX mailing 
list](https://github.com/apache/apisix/tree/master#community) first)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to