AWS - Using @connections websocket call back url t

2020-07-23 04:00发布

I have been struggling to send a response to connected clients through aws provided callback url(https://******.execute-api.us-east-1.amazonaws.com/test/@connections).

Have the below code in my backend to send the response which is one way communication.

    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);

Getting the Service: AmazonApiGatewayManagementApi; Status Code: 403; Error Code: InvalidSignatureException exception.

Note: I have everything setup like certificates and aws access keys.

As mentioned in the aws doc, I have tried with awscurl which is working. I am able to see the response on websocket connected clients. https://docs.amazonaws.cn/en_us/apigateway/latest/developerguide/apigateway-how-to-call-websocket-api-connections.html

0条回答
登录 后发表回答