Skip to content
This repository was archived by the owner on Feb 22, 2019. It is now read-only.

Repository files navigation

Serverless Websockets Plugin

Deprecation Notice

This repo is now deprecated, and we are no longer maintaining it. v1.38.0 of the framework now includes built-in support for websockets. Please check the docs for more info

1. Installation

Install the plugin by adding it to your service dependencies:

npm i serverless-websockets-plugin --save

Note: Because this plugin uses the new ApiGatewayV2 service in the AWS SDK, it requires v1.35.0+ of the Serverless Framework.

2. Usage

Load the serverless-websockets-plugin, then optionally provide a new API name and Route Selection Expression, and finally define your WebSockets events and their route keys:

service: serverless-websockets-service# Load the pluginplugins:
- serverless-websockets-pluginprovider:
name: awsruntime: nodejs8.10# OptionalwebsocketApiName: foobarwebsocketApiRouteSelectionExpression: $request.body.actionfunctions:
connectionManagement:
handler: handler.connectionManagementevents:
- websocket:
routeKey: $connect
- websocket:
routeKey: $disconnectdefaultMessage:
handler: handler.defaultevents:
- websocket:
routeKey: $defaultchatMessage:
handler: handler.chatevents:
- websocket:
routeKey: messagetwoWayMessage:
handler: handler.twoWayevents:
- websocket:
routeKey: twoway# The property below will enable an integration response in the API Gateway.# See https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api-route-response.htmlrouteResponseSelectionExpression: $default

About

Websocket support for Serverless Framework on AWS

Resources

Stars

147 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages