feat(aws-apigateway): method/integration responses, mapping templates, MOCK (A2) - #1441
Merged
Merged
Conversation
| func toInt(v any) (int, bool) { | ||
| switch t := v.(type) { | ||
| case int64: | ||
| return int(t), true |
| case int64: | ||
| return int(t), true | ||
| case float64: | ||
| return int(t), true |
…e cache (A2 review)
…deadline JSONPath walks, byte-capped template cache
NitinKumar004
marked this pull request as ready for review
October 4, 2026 13:32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A2 from the API Gateway REST build-out. MOCK integrations used to return 502 on invoke. They now run end to end: the request template picks the status, an integration response is selected by
selectionPattern, its mapping template renders the body, and its parameter mappings set the response headers. HTTP and HTTP_PROXY stay 502 until A3, as the plan scopes them.Control plane
PUT/GET/PATCH/DELETE .../methods/{m}/responses/{code}. A duplicate put givesConflictException, and an unknown code givesNotFoundException: Invalid Response status code specified..../integration/responses/{code}. The method must already declare the status code.responseParameterskeys must name headers the method response declares, and an invalidselectionPatternis rejected.requestTemplates,requestParameters,passthroughBehavior(validated),contentHandling,cacheNamespace(defaults to the resource id),cacheKeyParametersandcredentials.GetIntegrationandGetMethodnow embedintegrationResponsesandmethodResponses.requestParameters,requestModelsandoperationName, all patchable.Data plane (MOCK)
application/json.passthroughBehavioris applied: when NEVER, or WHEN_NO_TEMPLATES with templates defined, an unmatched type gets 415{"message": "Unsupported Media Type"}.application/jsonand then to the first template, and the response Content-Type follows the chosen template.$context.responseOverride.statusand.headerare honoured.{"message": "Internal server error"}withx-amzn-ErrorType.$input(body,json,path,params),$context,$stageVariablesand$util(escapeJavaScript,parseJson,urlEncode/urlDecode,base64Encode/base64Decode).Shared pieces
internal/vtlthat the plan describes (§3.3). It covers#set/#if/#elseif/#else/#foreach/#break/#stop/#return, comments, references, literals, ranges, maps, operators, and the String/List/Map method bridge.#foreachis capped at 1000 iterations, every render has a step budget and a deadline, and#macro/#parse/#include/#evaluate/#defineare rejected.internal/jsonpath, so ASL and the mapping templates share one implementation. ASL error messages are unchanged.New state lives on the existing driver structs, so snapshot/restore and the deployment trees carry it without extra code. There is a round-trip test for that.
Limits
Templates are untrusted input, so the engine bounds every way they can grow:
(this Collection)/(this Map). Encoding one as JSON is an error.InternalServerErrorExceptionresponse.split,replaceAll,replaceFirst) find one match at a time and charge each one before the next search. Literal patterns don't use the regex engine. Patterns with^,\A,\bor\Bfall back to doubling batches, and each batch is checked against the budget before it runs. Patterns over 64 KB are rejected.$input.pathwalks check the template deadline every 1024 nodes. The Step Functions path (jsonpath.Eval) is unchanged.$util.urlEncodenow matches Java's URLEncoder (~is encoded,*is left alone).escapeJavaScriptleaves 0x7F as is.$input.pathand$input.jsonsupport[*],.*and... Indefinite paths return a list, as Jayway does, and the number of matches is capped. Step Functions JSONPath still rejects these forms.Testing
development.serve: a self-referencing list or map returns 200 and prints itself, and the string and list doubling templates return 500 in about 5 ms and 30 ms. serve stays up, and RSS peaks at about 150 MB (47 MB idle).serve: 50 parallel requests, each with a 6 MB&a&a…body split by the request template, all return 500 within a second. Peak RSS is about 790 MB. A template that does no allocation peaks at about 740 MB on the same 50 bodies, so nearly all of that is the HTTP layer holding the request bodies, and templates add about 45 MB. Before this change the same run reached 3.5 GB.go build ./.... Vet and-racetests pass on the touched packages,persistandserver/aws(includingTestEveryHandlerDeclaresAuthorization).golangci-lint --new-from-revreports 0 issues. Coverage docs are regenerated.serve:4\d\d;aws_api_gateway_integration(MOCK,request_templates),aws_api_gateway_method_responseandaws_api_gateway_integration_response: apply, plan clean, update (template, header mapping, response model), plan clean, destroy.