【发布时间】:2019-10-25 13:20:05
【问题描述】:
我一直在努力通过 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
【问题讨论】:
标签: java amazon-web-services websocket api-gateway