使用CloudFortification将集成响应添加到AWS WebSocket API [英] Adding integration response to AWS websocket API with CloudFormation

查看:26
本文介绍了使用CloudFortification将集成响应添加到AWS WebSocket API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AWSrecently released Cloudformation support for templating websocket API gateways。我已经部署了一个正在运行的示例,但是我不知道如何打开代理集成响应(请参见屏幕截图了解如何在控制台中完成此操作)。有人知道什么CloudFortification设置可以用来打开lambda代理集成的默认集成响应吗?

推荐答案

请尝试以下步骤

1-在路由中将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

这篇关于使用CloudFortification将集成响应添加到AWS WebSocket API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆