AWS recently released Cloudformation support for templating websocket API gateways https://aws.amazon.com/about-aws/whats-new/2019/02/automate-websocket-api-creation-in-api-gateway-with-cloudformation/. 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?
请尝试以下步骤
1- 在 Route 中添加 RouteResponseSelectionExpression 作为 $default(目前仅支持一种)
2-为所有路由创建RouteResponse(双向)
注意:- RouteResponseKey: $default // 只能是默认值
3-添加ConnectIntegResponse(可选)
以下是经过测试的 CFN 片段,请随意使用
##########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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)