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

Bug: sam local includes extraneous version attribute in ApiGatewayLambdaEvent (incompatible with aws-lambda-rust-runtime) #6442

Closed
ramosbugs opened this issue Dec 12, 2023 · 4 comments
Labels
area/local stage/waiting-for-release Fix has been merged to develop and is waiting for a release type/bug

Comments

@ramosbugs
Copy link
Contributor

Description:

#1942 added support for API Gateway HTTP (aka v2) APIs to sam local. This change also modified the API Gateway REST API (aka v1) request payload to include a "version": "1.0" attribute that is not part of the payload that API Gateway includes in production.

This extraneous version attribute breaks compatibility with runtimes like the aws-lambda-rust-runtime that reject payloads that include unexpected fields.

As a consequence, the current versions of aws-sam-cli and aws-lambda-rust-runtime are mutually incompatible with one another for local testing. This is quite frustrating.

Since sam local is supposed to behave identically (as much as possible) to the corresponding AWS services, I feel the version attribute should be removed from ApiGatewayLambdaEvent:

self.version = "1.0"

Steps to reproduce:

  1. Define an AWS::Serverless::Api resource and corresponding Lambda proxy integration
  2. Run sam local

Observed result:

Lambda receives a request payload that includes "version": "1.0" (not present in API Gateway payloads).

Expected result:

Lambda should receive a request payload without version that mirrors the payload API Gateway sends in production.

@ramosbugs ramosbugs added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Dec 12, 2023
@hnnasit
Copy link
Contributor

hnnasit commented Dec 14, 2023

Hi @ramosbugs, thanks for reporting the issue. I see your PR in aws-lambda-rust-runtime got merged. Does that unblock you? As for the version field, I do see it in the docs for both the versions of API Gateway.

@hnnasit hnnasit added area/local type/question and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Dec 14, 2023
@ramosbugs
Copy link
Contributor Author

Hi @ramosbugs, thanks for reporting the issue. I see your PR in aws-lambda-rust-runtime got merged. Does that unblock you?

Yup, but I think this is still a bug in aws-sam-cli worth fixing.

As for the version field, I do see it in the docs for both the versions of API Gateway.

API Gateway HTTP APIs support two payload versions, which is what that link documents. API Gateway REST APIs do not have a version field: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format

It's easy to confuse because HTTP APIs are sometimes called v2 APIs, and REST APIs are sometimes called v1 APIs, but this nomenclature is independent of the HTTP API payload versioning represented by the version field:

Quote from the docs you linked above:

If you create a Lambda integration by using the AWS CLI, AWS CloudFormation, or an SDK, you must specify a payloadFormatVersion. The supported values are 1.0 and 2.0.

In this repo, I believe ApiGatewayLambdaEvent represents a REST API payload that shouldn't include a version. ApiGatewayV2LambdaEvent represents an HTTP API that seems to also use payload version 2.0 (although I see from the tests there is some support for version 1.0 HTTP API payloads as well: see http_v1_payload_route compared with api_gateway_route):

self.api_gateway_route = Route(
methods=["GET"],
function_name=self.function_name,
path="/",
operation_name="getRestApi",
)
self.http_gateway_route = Route(
methods=["GET"], function_name=self.function_name, path="/", event_type=Route.HTTP
)
self.http_v1_payload_route = Route(
methods=["GET"],
function_name=self.function_name,
path="/v1",
event_type=Route.HTTP,
payload_format_version="1.0",
operation_name="getV1",
)
self.http_v2_payload_route = Route(
methods=["GET"],
function_name=self.function_name,
path="/v2",
event_type=Route.HTTP,
payload_format_version="2.0",
operation_name="getV2",
)
self.http_v2_default_payload_route = Route(
methods=["x-amazon-apigateway-any-method"],
function_name=self.function_name,
path="$default",
event_type=Route.HTTP,
payload_format_version="2.0",
# no operation_name for default route
)

@hnnasit
Copy link
Contributor

hnnasit commented Dec 18, 2023

Thanks for providing the detailed references @ramosbugs. Marking this as a bug for the team to check if the field version can be removed without breaking any existing customers.

@sidhujus sidhujus added the stage/waiting-for-release Fix has been merged to develop and is waiting for a release label Jan 9, 2024
Copy link
Contributor

Patch is released in v1.107.0. Closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/local stage/waiting-for-release Fix has been merged to develop and is waiting for a release type/bug
Projects
None yet
Development

No branches or pull requests

3 participants