8000 fix APIGW AWS_PROXY lambda response validation by bentsku · Pull Request #11856 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content

fix APIGW AWS_PROXY lambda response validation #11856

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

Merged
merged 1 commit into from
Nov 15, 2024

Conversation

bentsku
Copy link
Contributor
@bentsku bentsku commented Nov 15, 2024

Motivation

We got a report in our Community Slack regarding too strict lambda payload response validation for the AWS_PROXY integration:

2024-11-15T05:30:24.755  WARN --- [et.reactor-1] l.s.a.n.e.integrations.aws : Lambda output should follow the next JSON format: { "isBase64Encoded": true|false, "statusCode": httpStatusCode, "headers": { "headerName": "headerValue", ... },"body": "..."} but was: b'{"statusCode":200,"headers":null,"multiValueHeaders":{"Content-Type":["application/json"],"X-Request-Id":["fcc51e39-0a54-45c6-88f7-c1d81b5f7075"]},"body":"''
2024-11-15T05:30:24.755 DEBUG --- [et.reactor-1] l.s.a.n.e.integrations.aws : Execution failed due to configuration error: Malformed Lambda proxy response

It seems we were too strict, and didn't have this validated by tests. I've added a quite complete tests inspired by some of our other work.

I've also spotted an issue in our multi value headers handling which I've sneaked a fix for.

Changes

  • fix raising an exception when the headers was set to null
  • fix multi headers handling
  • add a test for all of this

@bentsku bentsku added aws:apigateway Amazon API Gateway semver: patch Non-breaking changes which can be included in patch releases labels Nov 15, 2024
@bentsku bentsku self-assigned this Nov 15, 2024
@bentsku bentsku requested a review from cloutierMat as a code owner November 15, 2024 18:07
@bentsku bentsku added this to the 4.0 milestone Nov 15, 2024
Copy link
github-actions bot commented Nov 15, 2024

LocalStack Community integration with Pro

  2 files  ±    0    2 suites  ±0   25m 40s ⏱️ - 1h 17m 54s
808 tests  - 2 717  766 ✅  - 2 366  42 💤  - 351  0 ❌ ±0 
810 runs   - 2 717  766 ✅  - 2 366  44 💤  - 351  0 ❌ ±0 

Results for commit f346239. ± Comparison against base commit 385a141.

This pull request removes 2718 and adds 1 tests. Note that renamed tests count towards both.
tests.aws.scenario.bookstore.test_bookstore.TestBookstoreApplication ‑ test_lambda_dynamodb
tests.aws.scenario.bookstore.test_bookstore.TestBookstoreApplication ‑ test_opensearch_crud
tests.aws.scenario.bookstore.test_bookstore.TestBookstoreApplication ‑ test_search_books
tests.aws.scenario.bookstore.test_bookstore.TestBookstoreApplication ‑ test_setup
tests.aws.scenario.kinesis_firehose.test_kinesis_firehose.TestKinesisFirehoseScenario ‑ test_kinesis_firehose_s3
tests.aws.scenario.lambda_destination.test_lambda_destination_scenario.TestLambdaDestinationScenario ‑ test_destination_sns
tests.aws.scenario.lambda_destination.test_lambda_destination_scenario.TestLambdaDestinationScenario ‑ test_infra
tests.aws.scenario.loan_broker.test_loan_broker.TestLoanBrokerScenario ‑ test_prefill_dynamodb_table
tests.aws.scenario.loan_broker.test_loan_broker.TestLoanBrokerScenario ‑ test_stepfunctions_input_recipient_list[step_function_input0-SUCCEEDED]
tests.aws.scenario.loan_broker.test_loan_broker.TestLoanBrokerScenario ‑ test_stepfunctions_input_recipient_list[step_function_input1-SUCCEEDED]
…
tests.aws.services.apigateway.test_apigateway_lambda ‑ test_aws_proxy_response_payload_format_validation

♻️ This comment has been updated with latest results.

@bentsku bentsku force-pushed the fix-apigw-proxy-validation branch from f8a00e4 to f346239 Compare November 15, 2024 18:30
Copy link
Contributor
@cloutierMat cloutierMat left a comment

Choose a reason for hiding this comment

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

Solid fix! awesome that we can catch some of these already before the v4 realease! 🚀

Comment on lines +1060 to +1068
response = _invoke(
body={
"statusCode": 200,
"multiValueHeaders": {"tesT-Multi": ["value-multi"]},
"headers": {"test-multi": "value-solo"},
},
return_headers=True,
)
snapshot.match("invoke-api-multi-headers-overwrite-casing", response)
Copy link
Contributor

Choose a reason for hiding this comment

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

That is an interesting case!

@bentsku bentsku merged commit ee959cf into master Nov 15, 2024
31 checks passed
@bentsku bentsku deleted the fix-apigw-proxy-validation branch November 15, 2024 18:54
6AE8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws:apigateway Amazon API Gateway semver: patch Non-breaking changes which can be included in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0