WebSocketApiProps

class aws_cdk.aws_apigatewayv2.WebSocketApiProps(*, api_key_selection_expression=None, api_name=None, connect_route_options=None, default_route_options=None, description=None, disconnect_route_options=None, route_selection_expression=None)

Bases: object

Props for WebSocket API.

Parameters:
  • api_key_selection_expression (Optional[WebSocketApiKeySelectionExpression]) – An API key selection expression. Providing this option will require an API Key be provided to access the API. Default: - Key is not required to access these APIs

  • api_name (Optional[str]) – Name for the WebSocket API resource. Default: - id of the WebSocketApi construct.

  • connect_route_options (Union[WebSocketRouteOptions, Dict[str, Any], None]) – Options to configure a ‘$connect’ route. Default: - no ‘$connect’ route configured

  • default_route_options (Union[WebSocketRouteOptions, Dict[str, Any], None]) – Options to configure a ‘$default’ route. Default: - no ‘$default’ route configured

  • description (Optional[str]) – The description of the API. Default: - none

  • disconnect_route_options (Union[WebSocketRouteOptions, Dict[str, Any], None]) – Options to configure a ‘$disconnect’ route. Default: - no ‘$disconnect’ route configured

  • route_selection_expression (Optional[str]) – The route selection expression for the API. Default: ‘$request.body.action’

ExampleMetadata:

infused

Example:

from aws_cdk.aws_apigatewayv2_authorizers import WebSocketLambdaAuthorizer
from aws_cdk.aws_apigatewayv2_integrations import WebSocketLambdaIntegration

# This function handles your auth logic
# auth_handler: lambda.Function

# This function handles your WebSocket requests
# handler: lambda.Function


authorizer = WebSocketLambdaAuthorizer("Authorizer", auth_handler)

integration = WebSocketLambdaIntegration("Integration", handler)

apigwv2.WebSocketApi(self, "WebSocketApi",
    connect_route_options=apigwv2.WebSocketRouteOptions(
        integration=integration,
        authorizer=authorizer
    )
)

Attributes

api_key_selection_expression

An API key selection expression.

Providing this option will require an API Key be provided to access the API.

Default:
  • Key is not required to access these APIs

api_name

Name for the WebSocket API resource.

Default:
  • id of the WebSocketApi construct.

connect_route_options

Options to configure a ‘$connect’ route.

Default:
  • no ‘$connect’ route configured

default_route_options

Options to configure a ‘$default’ route.

Default:
  • no ‘$default’ route configured

description

The description of the API.

Default:
  • none

disconnect_route_options

Options to configure a ‘$disconnect’ route.

Default:
  • no ‘$disconnect’ route configured

route_selection_expression

The route selection expression for the API.

Default:

‘$request.body.action’