此问题可能是由于API网关未正确配置所致。以下是一个示例配置,可确保向所有客户端发送Websockets消息:
{
"Type": "AWS::ApiGatewayV2::Api",
"Properties": {
"ProtocolType": "WEBSOCKET",
"Name": "example-api-websocket",
"RouteSelectionExpression": "$request.body.action",
"Tags": {
"Name": "example-api-websocket"
},
"CorsConfiguration": {
"AllowCredentials": true,
"AllowHeaders": [
"Content-Type"
],
"AllowMethods": [
"GET",
"POST"
],
"AllowOrigins": [
"*"
]
},
"RouteSettings": {
"DataTraceEnabled": true,
"DetailedMetricsEnabled": true
}
}
}
确保正确设置了“RouteSelectionExpression”,以便在发送消息时选择正确的路由。另外,检查在调用API时是否正确发送了正确的参数和格式化的负载。