AWS การสนับสนุน Cloudformation ที่เปิดตัวเมื่อเร็วๆ นี้สำหรับการสร้างเทมเพลตเกตเวย์ websocket API ฉันมีตัวอย่างการทำงานที่ใช้งานอยู่ แต่ฉันไม่สามารถระบุวิธีเปิดใช้งานการตอบกลับการรวมพร็อกซีได้ (ดูภาพหน้าจอสำหรับวิธีการดำเนินการนี้ในคอนโซล) ไม่มีใครรู้ว่าการตั้งค่า cloudFormation ใดที่สามารถใช้เพื่อเปิดการตอบสนองการรวมเริ่มต้นสำหรับการรวมพร็อกซีแลมบ์ดา
การเพิ่มการตอบสนองการรวมเข้ากับ AWS websocket API ด้วย CloudFormation
คำตอบ (1)
โปรดลองขั้นตอนด้านล่าง
1- เพิ่ม RouteResponseSelectionExpression ใน Route เป็น $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
person
ifti
schedule
09.06.2019
ขอบคุณคูณ 1,000 สำหรับคำตอบนี้ วันนี้ฉันติดอยู่โดยไม่รู้เกี่ยวกับ RouteResponseSelectionExpression ทั้งวัน
- person miyasudokoro; 26.07.2019
ฉันสามารถดูการตอบสนองเมื่อเพิ่มสิ่งนี้ลงในเส้นทาง
sendmessage
แต่เมื่อเพิ่มลงใน $connect
ฉันไม่เห็นการตอบสนองใด ๆ ที่กลับมายังไคลเอนต์ websocket นอกจากนี้ ดูเหมือนว่าไม่จำเป็นต้องใช้ IntegrationResponse อย่างน้อยสำหรับประเภทการรวม HTTP_PROXY
- person diegosasw; 19.05.2021