Thanks to visit codestin.com
Credit goes to github.com

Skip to content

APIGW: fix VTL $input.path and $input.json #12774

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 3 commits into from
Jun 19, 2025

Conversation

bentsku
Copy link
Contributor

@bentsku bentsku commented Jun 18, 2025

Motivation

I've noticed while working on other kind of VTL template that we were not handling $input.path and $input.json return values correctly when the body would be empty, or the JSONPath would point to a non-existent value or the body would not be JSON.

There were several reasons:

  • the default extract_jsonpath helper method from LocalStack builds the result in a list, and return an empty list if there are no result. Because of this, we can't differentiate if we're actually fetching an empty list via the JSONPath, or we actually did not find a match. We now properly return None and verify behavior
  • we would return an empty dict by default if there were no body, but this isn't the right behavior from AWS. We'd need new tests with request templates again to validate, I've checked it with the AWS console and multiple scenarios and external tests that this is the right behavior
  • we would not support string value as body when using input.path or input.json. In AWS, it does not fail but instead fallback to returning null

Changes

  • use special extract_jsonpath for VTL rendering to stop returning empty list when no match
  • stop returning an empty dict when there is no body when calling input.path or input.body
  • add tests case
  • update unit tests with finding from AWS console

Testing

External run number: 15740672033 (good for this change)

@bentsku bentsku self-assigned this Jun 18, 2025
@bentsku bentsku added aws:apigateway Amazon API Gateway semver: patch Non-breaking changes which can be included in patch releases labels Jun 18, 2025
@bentsku bentsku added this to the 4.6 milestone Jun 18, 2025
Copy link

github-actions bot commented Jun 18, 2025

Test Results - Preflight, Unit

21 635 tests  +5   19 978 ✅ +5   6m 8s ⏱️ -14s
     1 suites ±0    1 657 💤 ±0 
     1 files   ±0        0 ❌ ±0 

Results for commit 64fc1af. ± Comparison against base commit 67b3da6.

♻️ This comment has been updated with latest results.

Copy link

LocalStack Community integration with Pro

    2 files  ±    0      2 suites  ±0   19m 7s ⏱️ - 1h 26m 10s
1 137 tests  - 3 748  1 072 ✅  - 3 036  65 💤  - 712  0 ❌ ±0 
1 139 runs   - 3 748  1 072 ✅  - 3 036  67 💤  - 712  0 ❌ ±0 

Results for commit 64fc1af. ± Comparison against base commit 67b3da6.

This pull request removes 3748 tests.
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]
…

Copy link

Test Results (amd64) - Acceptance

7 tests  ±0   5 ✅ ±0   3m 12s ⏱️ +2s
1 suites ±0   2 💤 ±0 
1 files   ±0   0 ❌ ±0 

Results for commit 64fc1af. ± Comparison against base commit 67b3da6.

Copy link

Test Results (amd64) - Integration, Bootstrap

    5 files      5 suites   36m 25s ⏱️
1 161 tests 1 096 ✅ 65 💤 0 ❌
1 167 runs  1 096 ✅ 71 💤 0 ❌

Results for commit 64fc1af.

Copy link

Test Results - Alternative Providers

987 tests   589 ✅  31m 24s ⏱️
  4 suites  398 💤
  4 files      0 ❌

Results for commit 64fc1af.

@bentsku bentsku marked this pull request as ready for review June 18, 2025 18:25
@bentsku bentsku requested a review from cloutierMat as a code owner June 18, 2025 18:25
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.

Awesome! 🚀 Thanks for the added test and the good pr comment!

The fix is looking good, we are starting to iron out a lot of those edge cases 🎉

@bentsku bentsku merged commit c9e0279 into master Jun 19, 2025
50 checks passed
@bentsku bentsku deleted the apigw-fix-vtl-input-empty-value branch June 19, 2025 09:23
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