Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(aws-lambda): add requestContext field into aws-gateway-compatible input #9380

Merged
merged 5 commits into from
Oct 18, 2022

Conversation

windmgc
Copy link
Member

@windmgc windmgc commented Sep 6, 2022

Summary

This PR adds a new field requestContext into the lambda input data when the aws-lambda plugin is working in awsgateway_compatible mode.

The requestContext is part of the input data in lambda proxy integration, according to this AWS document page, and it contains many fields containing request related information on AWS API Gateway.

The aws-lambda plugin in Kong provides an AWS API Gateway compatible mode that can generate an input data similar with
the example provided in this doc, but it does not contain the requestContext field. When users are writing their lambda functions with some libraries like aws-serverless-java-container, it will check if the input data have the requestContext field, and if it does not exist, the request will be regarded as malformed.(For example, see this code snippet)

To make the input data sound more "compatible", this PR adds the requestContext field into the input data. Note that many fields in the formal requestContext cannot be fetched by Kong(like IAM-related information or Cognito-related auth info), so we're just providing a best-effort delivery here. We cannot make assurance that the requestContext provided by Kong has every information that the lambda function needs, and it is decided by the lambda function whether the whole payload containing requestContext can work normally or not. So the feature is just a good-to-have one.

Full changelog

  • Add requestContext field into awsgateway_compatible input data
  • Add related tests

Issue reference

This should fix FTI-2620, and #7641, in some cases.

@windmgc windmgc requested a review from a team as a code owner September 6, 2022 06:18
kong/plugins/aws-lambda/aws-serializer.lua Outdated Show resolved Hide resolved
-- Kong does not have the concept of stage, so we just let resource path be the same as path
local resourcePath = path

requestContext = {
Copy link
Member

@Tieske Tieske Sep 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the locals, most are not used, we can add the values in-line to the table below?

(nitpick: feel free to ignore)

@windmgc windmgc force-pushed the feat-lambda-plug-request-context branch 3 times, most recently from a833a1b to df5dad6 Compare September 13, 2022 03:05
@windmgc windmgc added this to the 3.1 milestone Sep 27, 2022
@windmgc windmgc force-pushed the feat-lambda-plug-request-context branch from df5dad6 to 55a6523 Compare October 18, 2022 06:18
@fffonion fffonion merged commit f05e4bf into Kong:master Oct 18, 2022
@windmgc windmgc deleted the feat-lambda-plug-request-context branch October 19, 2022 03:11
locao pushed a commit that referenced this pull request Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants