Skip to main content

Web Socket API

Add a Web Socket API resource to your Altostra project

The Web Socket API resource creates a WebSocket API Gateway.
To add a Web Socket API resource in the designer, go to the "Networking & Content Delivery" section and select the "Web Socket API" resource, or search "websocket" in the search box:

Web Socket API resource

Web Socket API properties

Web Socket API resource properties

Name:

type: string | required

  • Altostra will use Name property for generating a logical ID:
    • Only strict alpha-numeric characters will be used (by the restrictions of CFN)
    • If non alpha-numeric characters were used in the name, the logical ID will be generated by the resource type
    • Up to 64 characters

Route Selector Property:

type: string | required

Specifies the property in a request-body that will be used to match the request with an endpoint.
It specifies a JSON property that is expected to be present in the message payload.

If an endpoint matches the value of the specified property in a request-body, it is selected to process the request. The $default endpoint matches requests when the request-body is not a JSON object, does not have the specified property, or if there is no endpoint that matches the value of that property in the request-body.

For example, if your JSON messages contain an action property and you want to perform different actions based on this property, your route selector property might be action.
Your API endpoints would specify which action to perform by matching the value of the action property against the routes of the API endpoint.

Web Socket API Endpoint properties

Operation Mode:

type: string | required

  • Select if the returned value of the triggered lambda (or any other connection) is returned to the client.
  • Allowed values:
    • 1-way: The lambda return value is ignored and never returned to the client
    • 2-way: The lambda is expected to return an object with a body string-property.
      The value of the body property will always be sent back to the client as a response.

In both cases, the lambda can get the connectionId from the context parameter, and explicitly send messages to the client through the web socket.

Route:

type: string | required

  • This is the value that is expected once a Route Selector Property is evaluated.
    If this values matches the value from the Route Selector Property of the request body, this endpoint will be chosen to process the request.

Web Socket API connections

Web Socket API connections

The Web Socket API can connect to the following resources:

  • Compute
    • Lambda Function
      • Used for authorization users' requests when connecting to the web socket.

Web Socket Endpoint connections

AWeb Socket Endpoint connections

The Web Socket Endpoint can connect to the following resources:

  • Compute
    • Lambda Function
      • Used for handling incoming requests

Ready to Get Started?

Get Started for Free
© 2023 Altostra, Inc.