mirror of
https://github.com/floci-io/floci.git
synced 2026-11-29 16:35:29 -05:00
feat(apigatewayv2): support IntegrationSubtype and invoke SQS-SendMessage on HTTP APIs (#7969)
CreateIntegration, UpdateIntegration, GetIntegration(s), OpenAPI import and
AWS::ApiGatewayV2::Integration now carry IntegrationSubtype. A subtype is
accepted only on an HTTP API AWS_PROXY integration with payload format 1.0
(the default when a subtype is set), and its RequestParameters must map every
required member of the action and nothing it does not take. SQS-SendMessage is
the supported subtype. The JSON 1.1 path keeps RequestParameters keys as sent,
since subtype parameters are PascalCase member names.
An HTTP API route whose AWS_PROXY integration has an IntegrationSubtype now
runs that AWS service action instead of resolving a Lambda function from the
integration URI. RequestParameters are mapped at invoke time: static values,
whole expressions such as $request.body, $request.body.<JSONPath>,
$request.header/querystring/path, $context and $stageVariables, and
expressions embedded as ${request.header.X}. Region selects the action's
region. A required parameter that maps to nothing answers 400
MissingParameter. The response is 200 with the action's result in the
<Action>Response/<Action>Result envelope; an action error keeps its status.
Lambda AWS_PROXY and HTTP_PROXY dispatch are unchanged.
Every subtype AWS defines is now known, with its required and optional parameters from the AWS reference, so create and update validate all of them instead of rejecting the ones Floci does not invoke. Only SQS-SendMessage carries a service action.
The subtype check is a package-private static method, and OpenAPI import and reimport run it over every x-amazon-apigateway-integration while planning, before any route or integration is deleted or created.
$request.body.<path> read a scalar through json-path as a JsonNode and threw ClassCastException, which escaped as a 500. The value is now read as an Object and converted, and resolution runs inside the dispatch error handling.
MessageAttributes and MessageSystemAttributes are parsed as JSON templates first and expressions are resolved only inside their string values, so a header holding quotes or braces stays one literal string instead of adding attributes.
Subtype parameters also resolve accountId, apiId, domainName, httpMethod, path, requestTime, requestTimeEpoch, routeKey and stage from $context. A subtype without a service action answers 500 at invoke.
UpdateIntegration keeps a field the request leaves out, so an AWS::ApiGatewayV2::Integration update that drops IntegrationSubtype kept the old one. The provisioner now clears it explicitly, records the prior subtype in the rollback snapshot and restores it when the update fails.
A number or boolean value is read as its text, and an object or array value is a 400 BadRequestException instead of an unchecked conversion error.
Adds invoke cases for $request.body.<field>, a header that tries to break out of its MessageAttributes value, and $context variables; a stored-but-not-invoked SQS-PurgeQueue integration; a reimport with an invalid subtype that leaves the API unchanged; and number and object RequestParameters values on the JSON protocol. Queue creation now sits inside the cleanup block.
A MessageAttributes or MessageSystemAttributes value that does not parse as a JSON object was interpolated as raw text, so a request value could add or change members of the attributes object. It is now an InvalidParameterValue 400; whole source expressions such as $request.body.attributes or ${request.body.attributes} still resolve as before.
- A required parameter mapped to null or a blank string is rejected like a missing one.
- A MessageAttributes or MessageSystemAttributes value must be a JSON object or a source expression.
- Number and boolean RequestParameters values sent to the REST endpoints are read as text, and object or array values are a 400 instead of a ClassCastException.
- UpdateIntegration that adds a subtype to an integration without one, and sends no PayloadFormatVersion, stores 1.0 as CreateIntegration does.
- The create, update and OpenAPI import paths share one payload format default.
- $context.requestId is the request's gateway id, honouring a valid x-amzn-RequestId override, instead of a fresh UUID.
- $context.domainName is the Host the request arrived on, falling back to the execute-api host, and $context.domainPrefix, extendedRequestId and protocol resolve.
- $context.path carries the stage prefix for a named stage, as HTTP API authorizer identity sources do.
- An integration without a Region parameter calls the service in the API's region, or the default region when the request carried none.
An x-amazon-apigateway-integration in an AWS::ApiGatewayV2::Api Body dropped integrationSubtype and requestParameters, so the API was created with a plain AWS_PROXY integration that never reached the service action. Both are now passed to CreateIntegration, which validates them as it does for every other caller. The PayloadFormatVersion default for AWS::ApiGatewayV2::Integration uses the shared helper.
The rollback snapshot restored the subtype only when the integration had one, so a failed update that added a subtype left it in place. The snapshot's subtype is now restored as recorded, null included, and a subtype change no longer marks the update as one whose other fields cannot be rolled back.
The template reader now fails on trailing tokens, so a value such as {"a":1} trailing no longer passes CreateIntegration and then has its tail dropped. The call-time check on a resolved JSON parameter uses the same reader instead of the application ObjectMapper, so create and invoke accept the same values.
A parameter value starting with $ was taken as an expression even when it named no source, such as "$5 off" or the typo $request.heder.x, so it passed CreateIntegration and resolved to nothing on every call. CreateIntegration, UpdateIntegration and OpenAPI import now answer it with a BadRequestException. The accepted sources are $request.header., $request.querystring., $request.path., $request.body and $request.body., $context. and $stageVariables., checked for a whole-value expression, each embedded ${...} expression, and the string values of a JSON parameter's object. A $ elsewhere in a value stays static text, so mixed templates are unchanged.
UpdateIntegration replaced RequestParameters wholesale, so an update that
set one optional parameter on an SQS-SendMessage integration dropped
QueueUrl and MessageBody and then failed the required-parameter check.
AWS merges: a named key is added or replaced, a key sent as an empty
string is removed, and an omitted key is kept. The merge applies to every
HTTP API integration, and the subtype check runs on the merged map.
The AWS::ApiGatewayV2::Api Body path passed requestParameters through as
objects, so an object-valued MessageAttributes was rejected as not a
string. It now reads every value with the importer's own conversion: a
number or boolean as its text, and an object or array as its JSON text.
A whitespace-only value is a valid SQS message body, and how API Gateway
treats one is unmeasured, so create now applies the same isEmpty check
invoke does instead of rejecting blank values.
ApiGatewayV2Service.stringParameters already reads number and boolean values as text and rejects object and array values, so the handler no longer converts them too.
This commit is contained in:
1 parent
a3a718bf55
commit
8eaf5bf59c
14 files changed
+1414
-24
No files matched your search
@@ -838,6 +838,63 @@ authorizer's context into request headers, query strings, and paths. For a retur
|
||||
`requestParameters`. String, numeric, and boolean context values are rendered as
|
||||
text. This works with format `1.0` policy responses and format `2.0` simple responses.
|
||||
|
||||
HTTP API `AWS_PROXY` integrations accept every `integrationSubtype` AWS defines:
|
||||
`EventBridge-PutEvents`, `SQS-SendMessage`, `SQS-ReceiveMessage`, `SQS-DeleteMessage`,
|
||||
`SQS-PurgeQueue`, `AppConfig-GetConfiguration`, `Kinesis-PutRecord`,
|
||||
`StepFunctions-StartExecution`, `StepFunctions-StartSyncExecution` and
|
||||
`StepFunctions-StopExecution`. `requestParameters` name the action's inputs, and create, update
|
||||
and OpenAPI import and reimport check them against that subtype's required and optional
|
||||
parameters from the AWS reference. They reject a required parameter that is missing, null or
|
||||
empty, any other parameter name, a JSON parameter such as `MessageAttributes` that is neither a
|
||||
JSON object nor a whole expression, a name that is not a subtype, a subtype on a non-`AWS_PROXY`
|
||||
integration or a WebSocket API, and a `payloadFormatVersion` other than `1.0`. `1.0` is the default
|
||||
when a subtype is set, including on an update that adds a subtype to an integration that had none.
|
||||
A number or boolean parameter value is stored as its text, and an object or array value is
|
||||
rejected. `UpdateIntegration` merges `requestParameters` into the stored ones for every HTTP API
|
||||
integration, as AWS does: a key it names is added or replaced, a key whose value is an empty string
|
||||
is removed, and a key it leaves out is kept. The subtype check runs on the merged parameters, so an
|
||||
update that sets only `DelaySeconds` keeps `QueueUrl` and `MessageBody`, and one that sets `QueueUrl`
|
||||
to an empty string is rejected. Import and reimport check every integration in the document before changing anything,
|
||||
so a rejected reimport leaves the API as it was. CloudFormation carries `IntegrationSubtype` and
|
||||
`RequestParameters` from an `AWS::ApiGatewayV2::Integration` and from the
|
||||
`x-amazon-apigateway-integration` extension of an `AWS::ApiGatewayV2::Api` `Body`. OpenAPI import
|
||||
and a CloudFormation `Body` read a `requestParameters` value the same way: a number or boolean as
|
||||
its text, and an object or array as its JSON text, so an object `MessageAttributes` is accepted and
|
||||
an array one is rejected as not a JSON object. A CloudFormation
|
||||
update that drops `IntegrationSubtype` removes it from the integration, and a failed update that
|
||||
added one rolls back to an integration without it.
|
||||
|
||||
Only `SQS-SendMessage` is invoked: each request is sent to an SQS queue instead of a Lambda
|
||||
function. A request that reaches any other subtype answers `500` with
|
||||
`{"message":"Internal Server Error"}`. For `SQS-SendMessage`, `QueueUrl` and `MessageBody` are
|
||||
required, and `DelaySeconds`, `MessageAttributes`, `MessageDeduplicationId`, `MessageGroupId`,
|
||||
`MessageSystemAttributes` and `Region` are optional. A value is a static string, a whole
|
||||
expression, or text with expressions embedded as `${request.header.Authorization}`. The
|
||||
expressions are `$request.body`, `$request.body.<JSONPath>`, `$request.header.<name>`,
|
||||
`$request.querystring.<name>`, `$request.path.<name>`, `$stageVariables.<name>`, and these
|
||||
`$context` variables: `accountId`, `apiId`, `domainName`, `domainPrefix`, `extendedRequestId`,
|
||||
`httpMethod`, `path`, `protocol`, `requestTime`, `requestTimeEpoch`, `routeKey`, `stage`,
|
||||
`requestId`, `identity.sourceIp`, `authorizer.<key>` and `authorizer.claims.<claim>`. `requestId`
|
||||
and `domainName` are the values the rest of the gateway reports for the request, and `path`
|
||||
starts with the stage name, as in `/test/send`, except on the `$default` stage. An expression
|
||||
with any other source is rejected with `400 BadRequestException` on create, update and import,
|
||||
including one embedded as `${...}` or inside a JSON parameter's string values. A `$` inside static
|
||||
text without braces, as in `price $5`, stays literal. A `$context` variable outside the list
|
||||
resolves to nothing, or to an empty string where it is embedded. `MessageAttributes`
|
||||
and `MessageSystemAttributes` are JSON object templates: expressions are resolved only inside
|
||||
their string values, so a header holding quotes or braces stays one string value and cannot add
|
||||
attributes. This differs from AWS, which substitutes the raw text into the template before
|
||||
parsing it: a value that is meant to add JSON structure becomes one string here. A JSON parameter
|
||||
that is a whole expression and resolves to anything but a JSON object answers `400` with
|
||||
`InvalidParameterValue`. `Region` selects the queue's region; when it is absent or resolves to an
|
||||
empty string, the API's region is used. `QueueUrl` is sent as resolved, so a mapped value can
|
||||
name any queue in the emulator. A sent message answers `200` with
|
||||
`{"SendMessageResponse":{"ResponseMetadata":{"RequestId":...},"SendMessageResult":{...}}}`; a
|
||||
required parameter that resolves to nothing, such as an empty body for `$request.body`, answers
|
||||
`400` with `{"Error":{"Code":"MissingParameter",...}}` (a value of only whitespace is sent as it is,
|
||||
since SQS accepts it), and an SQS error is relayed in the same
|
||||
shape with its status. `credentialsArn` is stored but not enforced, as for every other integration.
|
||||
|
||||
A Lambda proxy integration's response is read as AWS reads it (measured): a function that raises, a
|
||||
format 1.0 result that is not an object with a `statusCode`, and a `statusCode` that is not a whole
|
||||
number from 100 to 599 (text that spells one, such as `"201"`, is taken) are answered `500` with
|
||||
|
||||
Reference in new issue
Block a user