API Gateway Websocket Integration with Rest Endpoint

0

I have been trying to convert our REST APIs running on EC2 instance to websocket APIs, by redericting we wanted to send event data in format of { body : { ... } , query : { .... } , headers : { ..... }, path : { .... } }, in the http integration request for the websocket API we want to dynamically set the body, query, headers and path params of the integration request, based on these event inputs. What would be the integration template for one of the parameter

1回答
0

To set the integration request parameters dynamically based on event data in an Amazon API Gateway WebSocket API, you can use the Velocity Template Language (VTL) in the integration request mapping template.

Here is an example integration request mapping template that sets the body, query, headers, and path parameters of the integration request based on the event data:

#set($inputRoot = $input.path('$')) { "body" : "$inputRoot.body", "query" : { #foreach($param in $inputRoot.query.keySet()) "$param" : "$inputRoot.query.get($param)" #if( $foreach.hasNext ),#end #end }, "headers" : { #foreach($param in $inputRoot.headers.keySet()) "$param" : "$inputRoot.headers.get($param)" #if( $foreach.hasNext ),#end #end }, "path" : { #foreach($param in $inputRoot.path.keySet()) "$param" : "$inputRoot.path.get($param)" #if( $foreach.hasNext ),#end #end } }

This template first sets the $inputRoot variable to the root of the input event data. It then sets the body, query, headers, and path parameters of the integration request to the corresponding values in the event data.

You can then use this integration request mapping template in the integration request of your WebSocket API to dynamically set the integration request parameters based on the event data.

SeanSi
回答済み 1年前
  • That didn't work for me and it seems maybe that only the REST or HTTP version of Gateway supports this. I can't quite understand why this wouldn't be supported in the websocket API, but the documentation clearly leaves it out so I wasn't surprised when it didn't work.

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ