WebSocketRouteOptions Struct
Options used to add route to the API.
| Source | aws-apigatewayv2/lib/websocket/route.ts |
|---|---|
| Type last changed |
Example
ts
import { WebSocketLambdaIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations';
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),
});
python
from aws_cdk.aws_apigatewayv2_integrations import WebSocketLambdaIntegration
# message_handler: lambda.Function
web_socket_api = apigwv2.WebSocketApi(self, "mywsapi")
apigwv2.WebSocketStage(self, "mystage",
web_socket_api=web_socket_api,
stage_name="dev",
auto_deploy=True
)
web_socket_api.add_route("sendMessage",
integration=WebSocketLambdaIntegration("SendMessageIntegration", message_handler)
)
java
import software.amazon.awscdk.aws_apigatewayv2_integrations.WebSocketLambdaIntegration;
Function messageHandler;
WebSocketApi webSocketApi = new WebSocketApi(this, "mywsapi");
WebSocketStage.Builder.create(this, "mystage")
.webSocketApi(webSocketApi)
.stageName("dev")
.autoDeploy(true)
.build();
webSocketApi.addRoute("sendMessage", WebSocketRouteOptions.builder()
.integration(new WebSocketLambdaIntegration("SendMessageIntegration", messageHandler))
.build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AwsApigatewayv2Integrations;
Function messageHandler;
var webSocketApi = new WebSocketApi(this, "mywsapi");
new WebSocketStage(this, "mystage", new WebSocketStageProps {
WebSocketApi = webSocketApi,
StageName = "dev",
AutoDeploy = true
});
webSocketApi.AddRoute("sendMessage", new WebSocketRouteOptions {
Integration = new WebSocketLambdaIntegration("SendMessageIntegration", messageHandler)
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"
var messageHandler Function
webSocketApi := apigwv2.NewWebSocketApi(this, jsii.String("mywsapi"))
apigwv2.NewWebSocketStage(this, jsii.String("mystage"), &WebSocketStageProps{
WebSocketApi: WebSocketApi,
StageName: jsii.String("dev"),
AutoDeploy: jsii.Boolean(true),
})
webSocketApi.AddRoute(jsii.String("sendMessage"), &WebSocketRouteOptions{
Integration: awscdk.NewWebSocketLambdaIntegration(jsii.String("SendMessageIntegration"), messageHandler),
})
Properties
authorizeroptionalIWebSocketRouteAuthorizerauthorizeroptionalIWebSocketRouteAuthorizerauthorizeroptionalIWebSocketRouteAuthorizerAuthorizeroptionalIWebSocketRouteAuthorizerAuthorizeroptionalIWebSocketRouteAuthorizer #The authorize to this route.
Default: No Authorizer
You can only set authorizer to a $connect route.
integrationWebSocketRouteIntegrationintegrationWebSocketRouteIntegrationintegrationWebSocketRouteIntegrationIntegrationWebSocketRouteIntegrationIntegrationWebSocketRouteIntegration required #The integration to be configured on this route.
returnResponseoptionalbooleanreturn_responseoptionalboolreturnResponseoptionalBooleanReturnResponseoptionalboolReturnResponseoptional*bool = false #Should the route send a response to the client.