Mat*_*ega 8 amazon-web-services websocket aws-cloudformation aws-api-gateway
AWS最近发布了对模板 websocket API 网关的 Cloudformation 支持。我部署了一个工作示例,但我不知道如何打开代理集成响应(有关如何在控制台中完成此操作,请参见屏幕截图)。有谁知道可以使用什么 cloudFormation 设置来打开 lambda 代理集成的默认集成响应?

ift*_*fti 15
请尝试以下步骤
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 webSocketRun Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1040 次 |
| 最近记录: |