Passing Cognito JWT via Websockets

I’m just really trying to figure out how serverless expects the Cognito auth token to be passed with a websockets connection.

I have an authoriser lambda on my websocket paths:

    handler: handler.connectionHandler
      - websocket:
          route: $connect
            arn: ${self:provider.environment.authoriserArn}
      - websocket:
          route: $disconnect
            arn: ${self:provider.environment.authoriserArn}

I was wondering how I actually pass the token from the client over the connection in order for the auth to trigger correctly.

I’ve tried with rxjs websocket and with protocols, but not really sure how the authoriser should handle the request (I cannot see any token in the params passed in). I don’t believe we can add headers to websockets:

private setupWebsockets(token: string) {
    const subjectConfig: WebSocketSubjectConfig<any> = {
      url: 'wss://',
      protocol: [

    this.subject = webSocket(subjectConfig);

        (msg) => console.log('message received: ' + msg),
        (err) => console.error(err),
        () => console.log('complete')


It actually doesn’t look like my authorizer is being created when I login and check it manually. When I try to, I cannot use Cognito directly. If this is the case, that we cannot use Cognito directly, it should state in the docs (

In my experience,
(a) Amazon Websockets does not support modifying the subprotocol as you are doing in your example, as shown here, That is why you are not seeing the token in your authorizer.
(b) Also your authorizer is not being created if you are using the latest version of severless(1.38). You might have to use the master. Full support for authorizer is for the 1.39 release.

Thanks! Looks to be the case :slight_smile: