WebSocketAwsIntegration

class aws_cdk.aws_apigatewayv2_integrations.WebSocketAwsIntegration(id, *, integration_method, integration_uri, content_handling=None, credentials_role=None, passthrough_behavior=None, request_parameters=None, request_templates=None, template_selection_expression=None, timeout=None)

Bases: WebSocketRouteIntegration

AWS WebSocket AWS Type Integration.

ExampleMetadata:

infused

Example:

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"
                    }
                }
            })
        }
    )
)
Parameters:
  • id (str) – id of the underlying integration construct.

  • integration_method (str) – Specifies the integration’s HTTP method type.

  • integration_uri (str) – Integration URI.

  • content_handling (Optional[ContentHandling]) – 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.

  • credentials_role (Optional[IRole]) – Specifies the credentials role required for the integration. Default: - No credential role provided.

  • passthrough_behavior (Optional[PassthroughBehavior]) – 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. There are three valid values: WHEN_NO_MATCH, WHEN_NO_TEMPLATES, and NEVER. Default: - No passthrough behavior required.

  • request_parameters (Optional[Mapping[str, str]]) – The request parameters that API Gateway sends with the backend request. Specify request parameters as key-value pairs (string-to-string mappings), with a destination as the key and a source as the value. Default: - No request parameter provided to the integration.

  • request_templates (Optional[Mapping[str, str]]) – A map of Apache Velocity templates that are applied on the request payload. Example:: { “application/json”: “{ "statusCode": 200 }” } Default: - No request template provided to the integration.

  • template_selection_expression (Optional[str]) – The template selection expression for the integration. Default: - No template selection expression provided.

  • timeout (Optional[Duration]) – The maximum amount of time an integration will run before it returns without a response. Must be between 50 milliseconds and 29 seconds. Default: Duration.seconds(29)

Methods

bind(*, route, scope)

Bind this integration to the route.

Parameters:
  • route (IWebSocketRoute) – The route to which this is being bound.

  • scope (Construct) – The current scope in which the bind is occurring. If the WebSocketRouteIntegration being bound creates additional constructs, this will be used as their parent scope.

Return type:

WebSocketRouteIntegrationConfig