Skip to content

Conversation

@bentsku
Copy link
Contributor

@bentsku bentsku commented Sep 29, 2025

Motivation

As part of our weekly report, I've spotted 2 issues with APIGW TestInvokeMethod:

  File "/opt/code/localstack/.venv/lib/python3.13/site-packages/localstack/services/apigateway/next_gen/execute_api/test_invoke.py", line 263, in run_test_invocation
    log = log_template(invocation_context, response_headers)
  File "/opt/code/localstack/.venv/lib/python3.13/site-packages/localstack/services/apigateway/next_gen/execute_api/test_invoke.py", line 104, in log_template
    endpoint_response_status_code=endpoint_resp.get("status_code"),
                                  ^^^^^^^^^^^^^^^^^
localstack.aws.api.core.CommonServiceException: exception while calling apigateway.TestInvokeMethod: 'NoneType' object has no attribute 'get'

and this one:

  File "/opt/code/localstack/.venv/lib/python3.13/site-packages/localstack/services/apigateway/next_gen/execute_api/test_invoke.py", line 234, in run_test_invocation
    invocation_context = create_test_invocation_context(test_request, deployment)
  File "/opt/code/localstack/.venv/lib/python3.13/site-packages/localstack/services/apigateway/next_gen/execute_api/test_invoke.py", line 219, in create_test_invocation_context
    resource_method = resource["resourceMethods"][http_method]
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
localstack.aws.api.core.CommonServiceException: exception while calling apigateway.TestInvokeMethod: 'POST'

The first one is because we probably didn't handle failed invocation, and always expected every failed to be present. We need to guard against None-values when calling .get(), and improve it all together. The solution is not bullet proof, because to have perfect logging, we need to store the log as we progress in the invocation to be able to "stop" at the right moment, where the exception happens.

The second one is because we did not handle the ANY values properly, and also did not handle failures when the method would not exist.

Changes

  • add new tests to cover the exceptions raised
  • improve exception handling in the TestInvokeMethod and add some fallbacks
  • sneaked a small fix with the kind of exception raised which was shown in the failing test
  • add better validation of existing methods

@bentsku bentsku added this to the 4.10 milestone Sep 29, 2025
@bentsku bentsku self-assigned this Sep 29, 2025
@bentsku bentsku added aws:apigateway Amazon API Gateway semver: patch Non-breaking changes which can be included in patch releases docs: skip Pull request does not require documentation changes notes: skip Pull request does not have to be mentioned in the release notes labels Sep 29, 2025
@bentsku bentsku modified the milestones: 4.10, 4.9 Sep 29, 2025
@github-actions
Copy link

LocalStack Community integration with Pro

    2 files      2 suites   17m 1s ⏱️
1 162 tests 1 094 ✅ 68 💤 0 ❌
1 164 runs  1 094 ✅ 70 💤 0 ❌

Results for commit ed9cd64.

@github-actions
Copy link

Test Results - Preflight, Unit

22 281 tests  ±0   20 538 ✅ ±0   15m 44s ⏱️ ±0s
     1 suites ±0    1 743 💤 ±0 
     1 files   ±0        0 ❌ ±0 

Results for commit ed9cd64. ± Comparison against base commit 76c3b50.

@github-actions
Copy link

Test Results (amd64) - Acceptance

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

Results for commit ed9cd64. ± Comparison against base commit 76c3b50.

@github-actions
Copy link

Test Results (amd64) - Integration, Bootstrap

    5 files      5 suites   34m 50s ⏱️
1 186 tests 1 119 ✅ 67 💤 0 ❌
1 192 runs  1 119 ✅ 73 💤 0 ❌

Results for commit ed9cd64.

@bentsku bentsku marked this pull request as ready for review September 29, 2025 21:04
Copy link
Member

@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.

Thanks for jumping on this! 🙏 LGTM

@bentsku bentsku merged commit 13a2c87 into main Sep 30, 2025
59 checks passed
@bentsku bentsku deleted the apigw-fix-test-invoke branch September 30, 2025 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aws:apigateway Amazon API Gateway docs: skip Pull request does not require documentation changes notes: skip Pull request does not have to be mentioned in the release notes 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.

3 participants