Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a 403 when trying to call a websocket

Hey I have a web socket deployed to AWS API gateway with a custom domain and lambda's backing it. I keep getting this error in web console when trying to interact with it through my angular app:

WebSocket connection to 'wss://customDomain/' failed: Error during WebSocket handshake: Unexpected response code: 403

I am not seeing anything in logs for API Gateway like anything is trying to hit it, and no function invocations on the lambda side.

I have a deployment for the gateway and best I can tell everything is setup correct. I am trying to move this apigateway from a shared legacy AWS account into a new one using the AWS-CDK so I can confirm from the code level that the setup should be correct.

like image 704
Kevin Avatar asked Oct 21 '25 09:10

Kevin


2 Answers

The error here was caused by the API gateway needing to be deployed. After adding the custom domain, I created a new deployment for the stage that was assigned to the custom domain.

When using CDK, you can also set the stage to auto deploy on changes by setting autoDeploy: true in your CfnStage definition. This was what I ultimately did.

like image 88
Jared Bates Avatar answered Oct 25 '25 09:10

Jared Bates


In addition to Jared's answer (which I'm grateful for as I was stumped for days) this is an example of what it would look like in your code if using WebSocketStage from @aws-cdk/aws-apigatewayv2-alpha:

new WebSocketStage(scope, 'WebSocketStage', {
    webSocketApi,
    stageName: 'your-env-name',
    autoDeploy: true,
});
like image 37
David Avatar answered Oct 25 '25 11:10

David



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!