gpt4 book ai didi

amazon-web-services - 使用 CloudFormation 添加对 AWS websocket API 的集成响应

转载 作者:行者123 更新时间:2023-12-01 10:19:41 24 4
gpt4 key购买 nike

AWS recently released Cloudformation support for templating websocket API gateways 。我部署了一个工作示例,但我无法弄清楚如何打开代理集成响应(有关如何在控制台中完成此操作的屏幕截图)。有谁知道什么 cloudFormation 设置可用于打开 lambda 代理集成的默认集成响应? enter image description here

最佳答案

请尝试以下步骤

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

关于amazon-web-services - 使用 CloudFormation 添加对 AWS websocket API 的集成响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54643795/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com