WebSocketMockIntegration Class
Mock WebSocket Integration.
Example
ts
import { WebSocketMockIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations';
const webSocketApi = new apigwv2.WebSocketApi(this, 'mywsapi');
new apigwv2.WebSocketStage(this, 'mystage', {
webSocketApi,
stageName: 'dev',
autoDeploy: true,
});
webSocketApi.addRoute('sendMessage', {
integration: new WebSocketMockIntegration('DefaultIntegration', {
requestTemplates: { 'application/json': JSON.stringify({ statusCode: 200 }) },
templateSelectionExpression: '\\$default',
}),
returnResponse: true,
});
python
from aws_cdk.aws_apigatewayv2_integrations import WebSocketMockIntegration
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=WebSocketMockIntegration("DefaultIntegration",
request_templates={"application/json": JSON.stringify({"status_code": 200})},
template_selection_expression="\\$default"
),
return_response=True
)
java
import software.amazon.awscdk.aws_apigatewayv2_integrations.WebSocketMockIntegration;
WebSocketApi webSocketApi = new WebSocketApi(this, "mywsapi");
WebSocketStage.Builder.create(this, "mystage")
.webSocketApi(webSocketApi)
.stageName("dev")
.autoDeploy(true)
.build();
webSocketApi.addRoute("sendMessage", WebSocketRouteOptions.builder()
.integration(WebSocketMockIntegration.Builder.create("DefaultIntegration")
.requestTemplates(Map.of("application/json", JSON.stringify(Map.of("statusCode", 200))))
.templateSelectionExpression("\\$default")
.build())
.returnResponse(true)
.build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AwsApigatewayv2Integrations;
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 WebSocketMockIntegration("DefaultIntegration", new WebSocketMockIntegrationProps {
RequestTemplates = new Dictionary<string, string> { { "application/json", JSON.Stringify(new Dictionary<string, int> { { "statusCode", 200 } }) } },
TemplateSelectionExpression = "\\$default"
}),
ReturnResponse = true
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"
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.NewWebSocketMockIntegration(jsii.String("DefaultIntegration"), &WebSocketMockIntegrationProps{
RequestTemplates: map[string]*string{
"application/json": JSON.stringify(map[string]*f64{
"statusCode": jsii.Number(200),
}),
},
TemplateSelectionExpression: jsii.String("\\$default"),
}),
ReturnResponse: jsii.Boolean(true),
})
Initializer
ts
new WebSocketMockIntegration(id: string, props?: WebSocketMockIntegrationProps)
python
WebSocketMockIntegration(id: str, props: typing.Optional[WebSocketMockIntegrationProps] = None)
java
new WebSocketMockIntegration(String id, WebSocketMockIntegrationProps props)
csharp
new WebSocketMockIntegration(string id, WebSocketMockIntegrationProps? props = null)
go
NewWebSocketMockIntegration(Id *string, Props WebSocketMockIntegrationProps)
Methods
bind(options: WebSocketRouteIntegrationBindOptions): WebSocketRouteIntegrationConfigdef bind(self, options: WebSocketRouteIntegrationBindOptions) -> WebSocketRouteIntegrationConfigpublic WebSocketRouteIntegrationConfig bind(WebSocketRouteIntegrationBindOptions options)public WebSocketRouteIntegrationConfig Bind(WebSocketRouteIntegrationBindOptions options)func Bind(Options WebSocketRouteIntegrationBindOptions) WebSocketRouteIntegrationConfig#Bind this integration to the route.