Skip to content

APIGW NG add Integration Response selection and parameter mapping #11135

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 4 commits into from
Jul 4, 2024

Conversation

bentsku
Copy link
Contributor

@bentsku bentsku commented Jul 3, 2024

Motivation

This PR starts implementing the Integration Response handler, who's responsible for selecting the right IntegrationResponse based on the response status code (or an errorMessage field very specific to the AWS integration with Lambda, which we will tackle later).

The handler should then do the response parameters mapping, then the VTL rendering of the body.
We do not test the handler yet, same as the Integration Request handler, as the behavior is incomplete yet.

Instead, we can focus on the integration response selection, and the response parameters mapping. All of the unit tests have been manually tested against AWS, with the console and a SSH tunnel with localhost.run to my own small flask server to be able to return arbitrary payload from my HTTP payload.

More informations about the different subjects of the PR:

Changes

  • implement the base of the Integration Response handler, still very WIP, with comments outlining what I currently think is happening
  • ported the current selectionPattern util to select the right integration response (thanks @dfangl for implementing it!) and unit test it
  • refactor the parameter mapping a bit to share code between request and response parameter mappings (code is still pretty similar, but has a few distinct difference, we could always refactor later on)
  • add the response parameter mapping logic
  • add unit tests for response parameter mapping

TODO

What's left to do:

  • add unit tests for Response Parameters by validating with AWS
  • add unit tests for selecting the integration response

@bentsku bentsku added aws:apigateway Amazon API Gateway semver: patch Non-breaking changes which can be included in patch releases labels Jul 3, 2024
@bentsku bentsku self-assigned this Jul 3, 2024
Copy link

github-actions bot commented Jul 3, 2024

LocalStack Community integration with Pro

  2 files  ±    0    2 suites  ±0   23m 31s ⏱️ - 1h 16m 14s
643 tests  - 2 513  598 ✅  - 2 159  45 💤  - 350  0 ❌ ±0 
645 runs   - 2 513  598 ✅  - 2 159  47 💤  - 350  0 ❌ ±0 

Results for commit b8e979d. ± Comparison against base commit 6ea7da3.

This pull request removes 2513 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]
…

♻️ This comment has been updated with latest results.

@bentsku bentsku force-pushed the apigw-ng-param-mapping-int-response branch from 5b79f77 to d4e624d Compare July 4, 2024 01:59
@bentsku bentsku marked this pull request as ready for review July 4, 2024 02:01
@bentsku bentsku requested a review from cloutierMat as a code owner July 4, 2024 02:01
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 PR. Nice structure to the handler.

I still have some doubt/questions around the AWS lambda integration and the differences in how it handles success/error, but I guess we will discover more as we complete it's handler. For now, it seems logic to proceed this way, as the error end up in the body for the mapping, so we need it here.

Really good and clear tests. Congrats!


return response_data_mapping

def _retrieve_parameter_from_variables_and_static(
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! That will be ready for reuse in the gateway responses as well when we get there!

try:
decoded_body = self._json_load(body)
except ValueError:
# x-amzn-errortype: InternalFailureException
Copy link
Contributor

Choose a reason for hiding this comment

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

🙏


# this was validated against AWS
assert mapping == {
"header": {"body_value": "{}"},
Copy link
Contributor

Choose a reason for hiding this comment

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

It's back 👻

@bentsku
Copy link
Contributor Author

bentsku commented Jul 4, 2024

I still have some doubt/questions around the AWS lambda integration and the differences in how it handles success/error, but I guess we will discover more as we complete it's handler. For now, it seems logic to proceed this way, as the error end up in the body for the mapping, so we need it here.

@cloutierMat yes, it's a bit specific, but it seems it's well documented in the documentation, and it seems it really happens at the Integration Response level, as they talk about the fact that the Integration will always return 200, success or failure. It seems like a small hacky solution on AWS side too! But we can see better later, yes. It might be that the AWS lambda integration might have some specificity. Surprise later 😄

@bentsku bentsku merged commit a409563 into master Jul 4, 2024
32 checks passed
@bentsku bentsku deleted the apigw-ng-param-mapping-int-response branch July 4, 2024 11:13
# override them if there are overrides.
# for the body, it will maybe depend on configuration?

response.headers.clear()
Copy link
Contributor Author

@bentsku bentsku Jul 4, 2024

Choose a reason for hiding this comment

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

@cloutierMat this might have been a bit too aggressive 😄 I think we might need to keep a few, HTTP related headers, like Content-Type, Content-Length, etc. Might need to keep a list, and selectively remove all other headers. We can quickly try it with an integration with no mappings I suppose!

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