Skip to content

Commit

Permalink
fix(aws-lambda): add missing version field into aws gateway compatibl…
Browse files Browse the repository at this point in the history
…e payload (#13018)

This PR adds a missing version field into the aws-lambda plugin's awsgateway_compatible payload.

The awsgateway_compatible field provides a way to send a wrapped request body which is compatible with the format of AWS API gateway's proxy integration. The format of the payload is described here: https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html#http-api-develop-integrations-lambda.proxy-format

Some framework/projects that used to build Lambda function may check the version field sent by API gateway, so that they can apply different extracting logic according to different versions of payload. For example the logic in mangum looks like: https://github.com/jordaneremieff/mangum/blob/6086c268f32571c01f18e20875430db14a0570bc/mangum/handlers/api_gateway.py#L157-L176

The PR adds the missing version field for better compatibility.

FTI-5949

(cherry picked from commit 204dd8d)
  • Loading branch information
windmgc committed May 15, 2024
1 parent 7bad8d4 commit 550b1ac
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: "**AWS-Lambda**: Fixed an issue that the `version` field is not set in the request payload when `awsgateway_compatible` is enabled."
type: bugfix
scope: Plugin
1 change: 1 addition & 0 deletions kong/plugins/aws-lambda/request-util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ local function aws_serializer(ctx, config)
end

local request = {
version = "1.0",
resource = ctx.router_matches.uri,
path = path,
httpMethod = var.request_method,
Expand Down
3 changes: 3 additions & 0 deletions spec/03-plugins/27-aws-lambda/05-aws-serializer_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ describe("[AWS Lambda] aws-gateway input", function()
local out = aws_serialize()

assert.same({
version = "1.0",
httpMethod = "GET",
path = "/123/strip/more",
resource = "/(?<version>\\d+)/strip",
Expand Down Expand Up @@ -172,6 +173,7 @@ describe("[AWS Lambda] aws-gateway input", function()
local out = aws_serialize()

assert.same({
version = "1.0",
httpMethod = "GET",
path = "/plain/strip/more",
resource = "/plain/strip",
Expand Down Expand Up @@ -269,6 +271,7 @@ describe("[AWS Lambda] aws-gateway input", function()
local out = aws_serialize()

assert.same({
version = "1.0",
body = tdata.body_out,
headers = {
["Content-Type"] = tdata.ct,
Expand Down

0 comments on commit 550b1ac

Please sign in to comment.