@aws-cdk_aws-apigatewayv2-alpha.WebSocketApi

class WebSocketApi (construct) ๐Ÿ”น

LanguageType name
.NETAmazon.CDK.AWS.Apigatewayv2.Alpha.WebSocketApi
Gogithub.com/aws/aws-cdk-go/awscdkapigatewayv2alpha/v2#WebSocketApi
Javasoftware.amazon.awscdk.services.apigatewayv2.alpha.WebSocketApi
Pythonaws_cdk.aws_apigatewayv2_alpha.WebSocketApi
TypeScript (source)@aws-cdk/aws-apigatewayv2-alpha ยป WebSocketApi

Implements IConstruct, IDependable, IResource, IWebSocketApi, IApi

Create a new API Gateway WebSocket API endpoint.

Example

import { WebSocketLambdaIntegration } from '@aws-cdk/aws-apigatewayv2-integrations-alpha';

const webSocketApi = new apigwv2.WebSocketApi(this, 'mywsapi');
new apigwv2.WebSocketStage(this, 'mystage', {
  webSocketApi,
  stageName: 'dev',
  autoDeploy: true,
});

declare const messageHandler: lambda.Function;
webSocketApi.addRoute('sendmessage', {
  integration: new WebSocketLambdaIntegration('SendMessageIntegration', messageHandler),
});

Initializer

new WebSocketApi(scope: Construct, id: string, props?: WebSocketApiProps)

Parameters

  • scope Construct
  • id string
  • props WebSocketApiProps

Construct Props

NameTypeDescription
apiKeySelectionExpression?๐Ÿ”นWebSocketApiKeySelectionExpressionAn API key selection expression.
apiName?๐Ÿ”นstringName for the WebSocket API resource.
connectRouteOptions?๐Ÿ”นWebSocketRouteOptionsOptions to configure a '$connect' route.
defaultRouteOptions?๐Ÿ”นWebSocketRouteOptionsOptions to configure a '$default' route.
description?๐Ÿ”นstringThe description of the API.
disconnectRouteOptions?๐Ÿ”นWebSocketRouteOptionsOptions to configure a '$disconnect' route.
routeSelectionExpression?๐Ÿ”นstringThe route selection expression for the API.

apiKeySelectionExpression?๐Ÿ”น

Type: WebSocketApiKeySelectionExpression (optional, default: Key is not required to access these APIs)

An API key selection expression.

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


apiName?๐Ÿ”น

Type: string (optional, default: id of the WebSocketApi construct.)

Name for the WebSocket API resource.


connectRouteOptions?๐Ÿ”น

Type: WebSocketRouteOptions (optional, default: no '$connect' route configured)

Options to configure a '$connect' route.


defaultRouteOptions?๐Ÿ”น

Type: WebSocketRouteOptions (optional, default: no '$default' route configured)

Options to configure a '$default' route.


description?๐Ÿ”น

Type: string (optional, default: none)

The description of the API.


disconnectRouteOptions?๐Ÿ”น

Type: WebSocketRouteOptions (optional, default: no '$disconnect' route configured)

Options to configure a '$disconnect' route.


routeSelectionExpression?๐Ÿ”น

Type: string (optional, default: '$request.body.action')

The route selection expression for the API.

Properties

NameTypeDescription
apiEndpoint๐Ÿ”นstringThe default endpoint for an API.
apiId๐Ÿ”นstringThe identifier of this API Gateway API.
env๐Ÿ”นResourceEnvironmentThe environment this resource belongs to.
node๐Ÿ”นNodeThe tree node.
stack๐Ÿ”นStackThe stack in which this resource is defined.
webSocketApiName?๐Ÿ”นstringA human friendly name for this WebSocket API.

apiEndpoint๐Ÿ”น

Type: string

The default endpoint for an API.


apiId๐Ÿ”น

Type: string

The identifier of this API Gateway API.


env๐Ÿ”น

Type: ResourceEnvironment

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.


node๐Ÿ”น

Type: Node

The tree node.


stack๐Ÿ”น

Type: Stack

The stack in which this resource is defined.


webSocketApiName?๐Ÿ”น

Type: string (optional)

A human friendly name for this WebSocket API.

Note that this is different from webSocketApiId.

Methods

NameDescription
addRoute(routeKey, options)๐Ÿ”นAdd a new route.
applyRemovalPolicy(policy)๐Ÿ”นApply the given removal policy to this resource.
grantManageConnections(identity)๐Ÿ”นGrant access to the API Gateway management API for this WebSocket API to an IAM principal (Role/Group/User).
metric(metricName, props?)๐Ÿ”นReturn the given named metric for this Api Gateway.
toString()๐Ÿ”นReturns a string representation of this construct.
static fromWebSocketApiAttributes(scope, id, attrs)๐Ÿ”นImport an existing WebSocket API into this CDK app.

addRoute(routeKey, options)๐Ÿ”น

public addRoute(routeKey: string, options: WebSocketRouteOptions): WebSocketRoute

Parameters

  • routeKey string
  • options WebSocketRouteOptions

Returns

  • WebSocketRoute

Add a new route.


applyRemovalPolicy(policy)๐Ÿ”น

public applyRemovalPolicy(policy: RemovalPolicy): void

Parameters

  • policy RemovalPolicy

Apply the given removal policy to this resource.

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).


grantManageConnections(identity)๐Ÿ”น

public grantManageConnections(identity: IGrantable): Grant

Parameters

  • identity IGrantable โ€” The principal.

Returns

  • Grant

Grant access to the API Gateway management API for this WebSocket API to an IAM principal (Role/Group/User).


metric(metricName, props?)๐Ÿ”น

public metric(metricName: string, props?: MetricOptions): Metric

Parameters

  • metricName string
  • props MetricOptions

Returns

  • Metric

Return the given named metric for this Api Gateway.


toString()๐Ÿ”น

public toString(): string

Returns

  • string

Returns a string representation of this construct.


static fromWebSocketApiAttributes(scope, id, attrs)๐Ÿ”น

public static fromWebSocketApiAttributes(scope: Construct, id: string, attrs: WebSocketApiAttributes): IWebSocketApi

Parameters

  • scope Construct
  • id string
  • attrs WebSocketApiAttributes

Returns

  • IWebSocketApi

Import an existing WebSocket API into this CDK app.