Skip to content
v2.274.0

WebSocketIntegration L2 construct ​

The integration for an API route.

Example ​

ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import * as cdk from 'aws-cdk-lib';
import { aws_apigatewayv2 as apigatewayv2 } from 'aws-cdk-lib';
import { aws_iam as iam } from 'aws-cdk-lib';

declare const role: iam.Role;
declare const webSocketApiRef: apigatewayv2.IWebSocketApiRef;
const webSocketIntegration = new apigatewayv2.WebSocketIntegration(this, 'MyWebSocketIntegration', {
  integrationType: apigatewayv2.WebSocketIntegrationType.AWS_PROXY,
  integrationUri: 'integrationUri',
  webSocketApi: webSocketApiRef,

  // the properties below are optional
  contentHandling: apigatewayv2.ContentHandling.CONVERT_TO_BINARY,
  credentialsRole: role,
  integrationMethod: 'integrationMethod',
  passthroughBehavior: apigatewayv2.PassthroughBehavior.WHEN_NO_MATCH,
  requestParameters: {
    requestParametersKey: 'requestParameters',
  },
  requestTemplates: {
    requestTemplatesKey: 'requestTemplates',
  },
  templateSelectionExpression: 'templateSelectionExpression',
  timeout: cdk.Duration.minutes(30),
});
python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
import aws_cdk as cdk
from aws_cdk import aws_apigatewayv2 as apigatewayv2
from aws_cdk import aws_iam as iam

# role: iam.Role
# web_socket_api_ref: apigatewayv2.IWebSocketApiRef

web_socket_integration = apigatewayv2.WebSocketIntegration(self, "MyWebSocketIntegration",
    integration_type=apigatewayv2.WebSocketIntegrationType.AWS_PROXY,
    integration_uri="integrationUri",
    web_socket_api=web_socket_api_ref,

    # the properties below are optional
    content_handling=apigatewayv2.ContentHandling.CONVERT_TO_BINARY,
    credentials_role=role,
    integration_method="integrationMethod",
    passthrough_behavior=apigatewayv2.PassthroughBehavior.WHEN_NO_MATCH,
    request_parameters={
        "request_parameters_key": "requestParameters"
    },
    request_templates={
        "request_templates_key": "requestTemplates"
    },
    template_selection_expression="templateSelectionExpression",
    timeout=cdk.Duration.minutes(30)
)
java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.*;
import software.amazon.awscdk.services.apigatewayv2.*;
import software.amazon.awscdk.services.iam.*;

Role role;
IWebSocketApiRef webSocketApiRef;

WebSocketIntegration webSocketIntegration = WebSocketIntegration.Builder.create(this, "MyWebSocketIntegration")
        .integrationType(WebSocketIntegrationType.AWS_PROXY)
        .integrationUri("integrationUri")
        .webSocketApi(webSocketApiRef)

        // the properties below are optional
        .contentHandling(ContentHandling.CONVERT_TO_BINARY)
        .credentialsRole(role)
        .integrationMethod("integrationMethod")
        .passthroughBehavior(PassthroughBehavior.WHEN_NO_MATCH)
        .requestParameters(Map.of(
                "requestParametersKey", "requestParameters"))
        .requestTemplates(Map.of(
                "requestTemplatesKey", "requestTemplates"))
        .templateSelectionExpression("templateSelectionExpression")
        .timeout(Duration.minutes(30))
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK;
using Amazon.CDK.AWS.Apigatewayv2;
using Amazon.CDK.AWS.IAM;

Role role;
IWebSocketApiRef webSocketApiRef;

var webSocketIntegration = new WebSocketIntegration(this, "MyWebSocketIntegration", new WebSocketIntegrationProps {
    IntegrationType = WebSocketIntegrationType.AWS_PROXY,
    IntegrationUri = "integrationUri",
    WebSocketApi = webSocketApiRef,

    // the properties below are optional
    ContentHandling = ContentHandling.CONVERT_TO_BINARY,
    CredentialsRole = role,
    IntegrationMethod = "integrationMethod",
    PassthroughBehavior = PassthroughBehavior.WHEN_NO_MATCH,
    RequestParameters = new Dictionary<string, string> {
        { "requestParametersKey", "requestParameters" }
    },
    RequestTemplates = new Dictionary<string, string> {
        { "requestTemplatesKey", "requestTemplates" }
    },
    TemplateSelectionExpression = "templateSelectionExpression",
    Timeout = Duration.Minutes(30)
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import cdk "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

var role Role
var webSocketApiRef IWebSocketApiRef

webSocketIntegration := awscdk.Aws_apigatewayv2.NewWebSocketIntegration(this, jsii.String("MyWebSocketIntegration"), &WebSocketIntegrationProps{
	IntegrationType: awscdk.*Aws_apigatewayv2.WebSocketIntegrationType_AWS_PROXY,
	IntegrationUri: jsii.String("integrationUri"),
	WebSocketApi: webSocketApiRef,

	// the properties below are optional
	ContentHandling: awscdk.*Aws_apigatewayv2.ContentHandling_CONVERT_TO_BINARY,
	CredentialsRole: role,
	IntegrationMethod: jsii.String("integrationMethod"),
	PassthroughBehavior: awscdk.*Aws_apigatewayv2.PassthroughBehavior_WHEN_NO_MATCH,
	RequestParameters: map[string]*string{
		"requestParametersKey": jsii.String("requestParameters"),
	},
	RequestTemplates: map[string]*string{
		"requestTemplatesKey": jsii.String("requestTemplates"),
	},
	TemplateSelectionExpression: jsii.String("templateSelectionExpression"),
	Timeout: cdk.Duration_Minutes(jsii.Number(30)),
})

Initializer ​

ts
new WebSocketIntegration(scope: Construct, id: string, props: WebSocketIntegrationProps)
python
WebSocketIntegration(scope: Construct, id: str, props: WebSocketIntegrationProps)
java
new WebSocketIntegration(Construct scope, String id, WebSocketIntegrationProps props)
csharp
new WebSocketIntegration(Construct scope, string id, WebSocketIntegrationProps props)
go
NewWebSocketIntegration(Scope Construct, Id *string, Props WebSocketIntegrationProps)

Construct Props ​

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 IAM role required for the integration.

Default: No IAM role required.

integrationMethodoptionalstringintegration_methodoptionalstrintegrationMethodoptionalStringIntegrationMethodoptionalstringIntegrationMethodoptional*string#
Specifies the integration's HTTP method type.

Default: No HTTP method required.

integrationTypeWebSocketIntegrationTypeintegration_typeWebSocketIntegrationTypeintegrationTypeWebSocketIntegrationTypeIntegrationTypeWebSocketIntegrationTypeIntegrationTypeWebSocketIntegrationTyperequired#
Integration 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 parameters required.

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 templates required.

  { "application/json": "{ \"statusCode\": 200 }" }
templateSelectionExpressionoptionalstringtemplate_selection_expressionoptionalstrtemplateSelectionExpressionoptionalStringTemplateSelectionExpressionoptionalstringTemplateSelectionExpressionoptional*string#
The template selection expression for the integration.

Default: No template selection expression required.

timeoutoptionalDurationtimeoutoptionalDurationtimeoutoptionalDurationTimeoutoptionalDurationTimeoutoptionalDuration= Duration.seconds(29)#
The maximum amount of time an integration will run before it returns without a response.

Must be between 50 milliseconds and 29 seconds.

webSocketApiIWebSocketApiRefweb_socket_apiIWebSocketApiRefwebSocketApiIWebSocketApiRefWebSocketApiIWebSocketApiRefWebSocketApiIWebSocketApiRefrequired#
The WebSocket API to which this integration should be bound.

Properties ​

The environment this resource belongs to.
notes

For resources that are created and managed in a Stack (those created by creating new class instances like new Role(), new Bucket(), etc.), this is always the same as the environment of the stack they belong to.

For referenced resources (those obtained from referencing methods like Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be different than the stack they were imported into.

integrationIdstringintegration_idstrintegrationIdStringIntegrationIdstringIntegrationId*stringrequired#
Id of the integration.
integrationRefIntegrationReferenceintegration_refIntegrationReferenceintegrationRefIntegrationReferenceIntegrationRefIntegrationReferenceIntegrationRefIntegrationReferencerequired#
A reference to a Integration resource.
nodeNodenodeNodenodeNodeNodeNodeNodeNoderequired#
The tree node.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#
Uniquely identifies this class.
stackStackstackStackstackStackStackStackStackStackrequired#
The stack in which this resource is defined.
webSocketApiIWebSocketApiweb_socket_apiIWebSocketApiwebSocketApiIWebSocketApiWebSocketApiIWebSocketApiWebSocketApiIWebSocketApirequired#
The WebSocket API associated with this integration.

Methods ​

applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#
Override the cross-stack reference strength for this resource.
notes · 1 parameter

When set, any cross-stack reference to this resource will use the specified mechanism instead of the global default determined by the @aws-cdk/core:defaultCrossStackReferences context key. This is useful for selectively weakening specific references to avoid the "deadly embrace" problem without changing the app-wide default.

Parameters

  • strengthstrengthstrengthstrengthStrength — - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#
Apply the given removal policy to this resource.
notes

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).

isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters

  • xxxxX — Any object.

Returns: true if x is an object created from a class which extends Construct.

isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#
Returns true if the construct was created by CDK, and false otherwise.
isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#
Check whether the given construct is a Resource.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#
Applies one or more mixins to this construct.

Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.