WebSocketAwsIntegrationProps Struct
Props for AWS type integration for a WebSocket Api.
Example
ts
import { WebSocketAwsIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations';
import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
import * as iam from 'aws-cdk-lib/aws-iam';
const webSocketApi = new apigwv2.WebSocketApi(this, 'mywsapi');
new apigwv2.WebSocketStage(this, 'mystage', {
webSocketApi,
stageName: 'dev',
autoDeploy: true,
});
declare const apiRole: iam.Role;
declare const table: dynamodb.Table;
webSocketApi.addRoute('$connect', {
integration: new WebSocketAwsIntegration('DynamodbPutItem', {
integrationUri: `arn:aws:apigateway:${this.region}:dynamodb:action/PutItem`,
integrationMethod: apigwv2.HttpMethod.POST,
credentialsRole: apiRole,
requestTemplates: {
'application/json': JSON.stringify({
TableName: table.tableName,
Item: {
id: {
S: '$context.requestId',
},
},
}),
},
}),
});
python
from aws_cdk.aws_apigatewayv2_integrations import WebSocketAwsIntegration
import aws_cdk.aws_dynamodb as dynamodb
import aws_cdk.aws_iam as iam
# api_role: iam.Role
# table: dynamodb.Table
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("$connect",
integration=WebSocketAwsIntegration("DynamodbPutItem",
integration_uri=f"arn:aws:apigateway:{this.region}:dynamodb:action/PutItem",
integration_method=apigwv2.HttpMethod.POST,
credentials_role=api_role,
request_templates={
"application/json": JSON.stringify({
"TableName": table.table_name,
"Item": {
"id": {
"S": "$context.requestId"
}
}
})
}
)
)
java
import software.amazon.awscdk.aws_apigatewayv2_integrations.WebSocketAwsIntegration;
import software.amazon.awscdk.services.dynamodb.*;
import software.amazon.awscdk.services.iam.*;
Role apiRole;
Table table;
WebSocketApi webSocketApi = new WebSocketApi(this, "mywsapi");
WebSocketStage.Builder.create(this, "mystage")
.webSocketApi(webSocketApi)
.stageName("dev")
.autoDeploy(true)
.build();
webSocketApi.addRoute("$connect", WebSocketRouteOptions.builder()
.integration(WebSocketAwsIntegration.Builder.create("DynamodbPutItem")
.integrationUri(String.format("arn:aws:apigateway:%s:dynamodb:action/PutItem", this.region))
.integrationMethod(HttpMethod.POST)
.credentialsRole(apiRole)
.requestTemplates(Map.of(
"application/json", JSON.stringify(Map.of(
"TableName", table.getTableName(),
"Item", Map.of(
"id", Map.of(
"S", "$context.requestId"))))))
.build())
.build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AwsApigatewayv2Integrations;
using Amazon.CDK.AWS.DynamoDB;
using Amazon.CDK.AWS.IAM;
Role apiRole;
Table table;
var webSocketApi = new WebSocketApi(this, "mywsapi");
new WebSocketStage(this, "mystage", new WebSocketStageProps {
WebSocketApi = webSocketApi,
StageName = "dev",
AutoDeploy = true
});
webSocketApi.AddRoute("$connect", new WebSocketRouteOptions {
Integration = new WebSocketAwsIntegration("DynamodbPutItem", new WebSocketAwsIntegrationProps {
IntegrationUri = $"arn:aws:apigateway:{this.region}:dynamodb:action/PutItem",
IntegrationMethod = HttpMethod.POST,
CredentialsRole = apiRole,
RequestTemplates = new Dictionary<string, string> {
{ "application/json", JSON.Stringify(new Dictionary<string, object> {
{ "TableName", table.TableName },
{ "Item", new Struct {
Id = new Struct {
S = "$context.requestId"
}
} }
}) }
}
})
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"
import dynamodb "github.com/aws/aws-cdk-go/awscdk"
import iam "github.com/aws/aws-cdk-go/awscdk"
var apiRole Role
var table Table
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("$connect"), &WebSocketRouteOptions{
Integration: awscdk.NewWebSocketAwsIntegration(jsii.String("DynamodbPutItem"), &WebSocketAwsIntegrationProps{
IntegrationUri: fmt.Sprintf("arn:aws:apigateway:%v:dynamodb:action/PutItem", this.Region),
IntegrationMethod: apigwv2.HttpMethod_POST,
CredentialsRole: apiRole,
RequestTemplates: map[string]*string{
"application/json": JSON.stringify(map[string]interface{}{
"TableName": table.tableName,
"Item": map[string]map[string]*string{
"id": map[string]*string{
"S": jsii.String("$context.requestId"),
},
},
}),
},
}),
})
Properties
contentHandlingoptionalContentHandlingcontent_handlingoptionalContentHandlingcontentHandlingoptionalContentHandlingContentHandlingoptionalContentHandlingContentHandlingoptionalContentHandling#Specifies how to handle response payload content type conversions.
Default: The response payload will be passed through from the integration response to the route response or method response without modification.
credentialsRoleoptionalIRolecredentials_roleoptionalIRolecredentialsRoleoptionalIRoleCredentialsRoleoptionalIRoleCredentialsRoleoptionalIRole#Specifies the credentials role required for the integration.
Default: No credential role provided.
integrationMethodstringintegration_methodstrintegrationMethodStringIntegrationMethodstringIntegrationMethod*stringrequired#Specifies the integration's HTTP method type.
integrationUristringintegration_uristrintegrationUriStringIntegrationUristringIntegrationUri*stringrequired#Integration URI.
passthroughBehavioroptionalPassthroughBehaviorpassthrough_behavioroptionalPassthroughBehaviorpassthroughBehavioroptionalPassthroughBehaviorPassthroughBehavioroptionalPassthroughBehaviorPassthroughBehavioroptionalPassthroughBehavior#Specifies the pass-through behavior for incoming requests based on the Content-Type header in the request, and the available mapping templates specified as the requestTemplates property on the Integration resource.
Default: No passthrough behavior required.
There are three valid values: WHEN_NO_MATCH, WHEN_NO_TEMPLATES, and NEVER.
requestParametersoptional{ [key: string]: string }request_parametersoptionaltyping.Mapping[str, str]requestParametersoptionalMap<String, String>RequestParametersoptionalIDictionary<string, string>RequestParametersoptional*map[string]*string#The request parameters that API Gateway sends with the backend request.
Default: No request parameter provided to the integration.
Specify request parameters as key-value pairs (string-to-string mappings), with a destination as the key and a source as the value.
requestTemplatesoptional{ [key: string]: string }request_templatesoptionaltyping.Mapping[str, str]requestTemplatesoptionalMap<String, String>RequestTemplatesoptionalIDictionary<string, string>RequestTemplatesoptional*map[string]*string#A map of Apache Velocity templates that are applied on the request payload.
Default: No request template provided to the integration.
{ "application/json": "{ \"statusCode\": 200 }" }
templateSelectionExpressionoptionalstringtemplate_selection_expressionoptionalstrtemplateSelectionExpressionoptionalStringTemplateSelectionExpressionoptionalstringTemplateSelectionExpressionoptional*string#The template selection expression for the integration.
Default: No template selection expression provided.