Reputation: 306
AWS recently released Cloudformation support for templating websocket API gateways. I have a working example deployed, but I can't work out how to turn on the proxy integration response (see screenshot for how this is done in the console). Does anyone know what cloudFormation setting can be used to turn on a default integration response for lambda proxy integrations?
Upvotes: 9
Views: 2226
Reputation: 669
Please try below steps
1- Add RouteResponseSelectionExpression in Route as $default(this is only one supported as of now)
2- Create RouteResponse for all routes(bidirectional) Note:- RouteResponseKey: $default // it should be default only
3- Add ConnectIntegResponse(Optional)
Below is a tested CFN snippet, feel free to use it
##########Socket API###############
webSocket:
Type: AWS::ApiGatewayV2::Api
Properties:
Name: WebSocket
ProtocolType: WEBSOCKET
RouteSelectionExpression: "$request.body.action"
ConnectRoute:
Type: AWS::ApiGatewayV2::Route
Properties:
ApiId: !Ref webSocket
RouteKey: $connect
AuthorizationType: NONE
OperationName: ConnectRoute
RouteResponseSelectionExpression: $default # add this
Target: !Join
- '/'
- - 'integrations'
- !Ref ConnectInteg
ConnectInteg:
Type: AWS::ApiGatewayV2::Integration
Properties:
ApiId: !Ref webSocket
Description: Connect Integration
IntegrationType: AWS_PROXY
IntegrationUri:
Fn::Sub:
arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${restAndSocketLambda.Arn}/invocations
ConnectRouteResponse: # Add this
Type: 'AWS::ApiGatewayV2::RouteResponse'
Properties:
RouteId: !Ref ConnectRoute
ApiId: !Ref webSocket
RouteResponseKey: $default
ConnectIntegResponse: # Add this(if required)
Type: 'AWS::ApiGatewayV2::IntegrationResponse'
Properties:
IntegrationId: !Ref ConnectInteg
IntegrationResponseKey: /201/
ApiId: !Ref webSocket
Upvotes: 22