From 550b1ac2da136c03b6d6f619e259815f0f6cf299 Mon Sep 17 00:00:00 2001 From: Keery Nie Date: Wed, 15 May 2024 10:25:00 +0800 Subject: [PATCH] fix(aws-lambda): add missing version field into aws gateway compatible 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 204dd8ddb406399473073e0bb263c4531f409a43) --- .../kong/fix-aws-lambda-gateway-compat-version-field.yml | 3 +++ kong/plugins/aws-lambda/request-util.lua | 1 + spec/03-plugins/27-aws-lambda/05-aws-serializer_spec.lua | 3 +++ 3 files changed, 7 insertions(+) create mode 100644 changelog/unreleased/kong/fix-aws-lambda-gateway-compat-version-field.yml diff --git a/changelog/unreleased/kong/fix-aws-lambda-gateway-compat-version-field.yml b/changelog/unreleased/kong/fix-aws-lambda-gateway-compat-version-field.yml new file mode 100644 index 000000000000..95dd88cfc824 --- /dev/null +++ b/changelog/unreleased/kong/fix-aws-lambda-gateway-compat-version-field.yml @@ -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 diff --git a/kong/plugins/aws-lambda/request-util.lua b/kong/plugins/aws-lambda/request-util.lua index 5e2891824c4a..06bc9acb52c4 100644 --- a/kong/plugins/aws-lambda/request-util.lua +++ b/kong/plugins/aws-lambda/request-util.lua @@ -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, diff --git a/spec/03-plugins/27-aws-lambda/05-aws-serializer_spec.lua b/spec/03-plugins/27-aws-lambda/05-aws-serializer_spec.lua index 5a5670e9c368..e96201c02136 100644 --- a/spec/03-plugins/27-aws-lambda/05-aws-serializer_spec.lua +++ b/spec/03-plugins/27-aws-lambda/05-aws-serializer_spec.lua @@ -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 = "/(?\\d+)/strip", @@ -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", @@ -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,