Hello, I have a simple websocket implementation that is working offline but fails in AWS. I can successfully connect but am not able to send a response with ApiGatewayManagementApi.postToConnection(). I am able to log a mysterious 403 in CloudFront:
ForbiddenException
at deserializeAws_restJson1PostToConnectionCommandError (/var/task/node_modules/@aws-sdk/client-apigatewaymanagementapi/dist/cjs/protocols/Aws_restJson1.js:287:41)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async /var/task/node_modules/@aws-sdk/middleware-serde/dist/cjs/deserializerMiddleware.js:6:20
at async /var/task/node_modules/@aws-sdk/middleware-signing/dist/cjs/middleware.js:12:24
at async StandardRetryStrategy.retry (/var/task/node_modules/@aws-sdk/middleware-retry/dist/cjs/defaultStrategy.js:56:46)
at async /var/task/node_modules/@aws-sdk/middleware-logger/dist/cjs/loggerMiddleware.js:6:22
at async PubSub.send (/var/task/PubSub.js:73:24)
at async Handler.wsConnection (/var/task/Handler.js:215:9) {
'$fault': 'client',
'$metadata': {
httpStatusCode: 403,
requestId: 'ae81fd40-74f8-4cf5-8da5-a896d8592941',
extendedRequestId: undefined,
cfId: undefined,
attempts: 1,
totalRetryDelay: 0
}
}
I am setting up my ApiGatewayManagementApi (in my class constructor):
this.api = new ApiGatewayManagementApi({
apiVersion: "2018-11-29",
endpoint: props.apiGatewayEndpoint, // https://{id-from-serverless-deploy}.execute-api.ca-central-1.amazonaws.com/dev
});
And calling:
const params = {
ConnectionId: connection, // Confirmed websocket connectionId
Data: Buffer.from(JSON.stringify(res)), // Confirmed JSON payload
};
const retVal = await this.api.postToConnection(params);
This particular postToConnection() is invoked after a successful connection and thus the associated serverless.yml section is (and works locally)
wsConnection:
handler: Handler.wsConnection
events:
- websocket:
route: $connect
- websocket:
route: $disconnect