-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
APIGW: migrate TestInvokeMethod to NextGen #12514
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
Conversation
LocalStack Community integration with Pro 2 files ± 0 2 suites ±0 29m 17s ⏱️ - 1h 23m 39s Results for commit 5560ff0. ± Comparison against base commit 073eab9. This pull request removes 3248 tests.
♻️ This comment has been updated with latest results. |
836bfdb
to
6421bf2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super impressive work! I really like the solution you came up with to facilitate snapshotting the logs.
I love how we can reuse the handler chain for this! 👍
# TODO: funny enough, in AWS for the `endpoint_response_headers` in AWS_PROXY, they log the response headers from | ||
# lambda HTTP Invoke call even though we use the headers from the lambda response itself |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😢 Never stop being surprised!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this is kinda weird 😄 somewhat leaking implementation details
def create_test_chain() -> HandlerChain[RestApiInvocationContext]: | ||
return HandlerChain( | ||
request_handlers=[ | ||
handlers.method_request_handler, | ||
handlers.integration_request_handler, | ||
handlers.integration_handler, | ||
handlers.integration_response_handler, | ||
handlers.method_response_handler, | ||
], | ||
exception_handlers=[ | ||
handlers.gateway_exception_handler, | ||
], | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So clean! This really makes that work we did shine bright!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And it was so nice to actually be able to only pick a few handlers that we needed, skipping the parsing and routing of the request 👌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean you could add them all, and have a if is_test_invoke
in them to produce a different result! 🤣
def _fix_headers(headers: Headers) -> Headers: | ||
headers.remove("Content-Length") | ||
|
||
return headers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this feels a bit out of place in the middle of the file 🫤 Maybe we could move it up with the _dump_headers
util?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah agreed, it did multiple things before like adding the trace-id, but it looked like MOCK wasn't adding it... so I've just added the removal of Content-Length
straight in the run method now. If we ever need to add more, we'll move it to its own function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the cleanup! 🙏
def _transform_log(_log: str) -> dict[str, str]: | ||
return {f"line{index:02d}": line for index, line in enumerate(_log.split("\n"))} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice attention! It will be much easier to see the error when it arises! 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the review! I've just realized that I hadn't re-ran the test against AWS after fixing some regex shenanigans, I'll fix it and merge. This was a fun one 😄
# TODO: funny enough, in AWS for the `endpoint_response_headers` in AWS_PROXY, they log the response headers from | ||
# lambda HTTP Invoke call even though we use the headers from the lambda response itself |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this is kinda weird 😄 somewhat leaking implementation details
def create_test_chain() -> HandlerChain[RestApiInvocationContext]: | ||
return HandlerChain( | ||
request_handlers=[ | ||
handlers.method_request_handler, | ||
handlers.integration_request_handler, | ||
handlers.integration_handler, | ||
handlers.integration_response_handler, | ||
handlers.method_response_handler, | ||
], | ||
exception_handlers=[ | ||
handlers.gateway_exception_handler, | ||
], | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And it was so nice to actually be able to only pick a few handlers that we needed, skipping the parsing and routing of the request 👌
def _fix_headers(headers: Headers) -> Headers: | ||
headers.remove("Content-Length") | ||
|
||
return headers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah agreed, it did multiple things before like adding the trace-id, but it looked like MOCK wasn't adding it... so I've just added the removal of Content-Length
straight in the run method now. If we ever need to add more, we'll move it to its own function?
Motivation
The
TestInvokeMethod
operation was still relying on the legacy invocation logic of API Gateway. This PR migrates it to not rely on old code anymore and use the new handler chain, create one and invoke it.I've also improved the test, it is now fully transformed and can run against AWS with snapshot validation enabled.
Also took the opportunity to remove some old "fixtures" doing nothing.
Changes