我一直在努力通过aws提供的回调URL(https://******.execute-api.us-east-1.amazonaws.com/test/@connections)向连接的客户端发送响应。
在我的后端中具有以下代码以发送响应,这是一种单向通信。
AwsClientBuilder.EndpointConfiguration config =
new AwsClientBuilder.EndpointConfiguration("https://*********.execute-api.us-east-1.amazonaws.com/test", "us-east-1");
AmazonApiGatewayManagementApi client = AmazonApiGatewayManagementApiClientBuilder.standard()
.withEndpointConfiguration(config).build();
PostToConnectionRequest request = new PostToConnectionRequest();
request.withConnectionId("bGYcWek5oAMCKwA=");
Charset charset = Charset.forName("UTF-8");
CharsetEncoder encoder = charset.newEncoder();
ByteBuffer buff = null;
try {
buff = encoder.encode(CharBuffer.wrap("Hello from lambda"));
} catch (CharacterCodingException e) {
log.error("Error while encoding", e);
}
request.withData(buff);
PostToConnectionResult result = client.postToConnection(request);
log.info("Result of websocket send:\n" + result);
获取服务:AmazonApiGatewayManagementApi;状态码:403;错误代码:InvalidSignatureException异常。
注意:我已完成所有设置,如证书和AWS访问密钥。
如aws文档中所述,我已经尝试了正在运行的awscurl。我能够在websocket连接的客户端上看到响应。https://docs.amazonaws.cn/en_us/apigateway/latest/developerguide/apigateway-how-to-call-websocket-api-connections.html
您是否找到了解决方案?完全一样的问题。