# WebSocketAwsIntegrationProps

Props for AWS type integration for a WebSocket Api.

Used as props by: [WebSocketAwsIntegration](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigatewayv2_integrations.WebSocketAwsIntegration.html)

- Source: [`aws-apigatewayv2-integrations/lib/websocket/aws.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-apigatewayv2-integrations/lib/websocket/aws.ts#L17)
- Type last changed: v2.134.0 · 26 Mar 2024

## Example

TypeScript:

```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:

```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:

```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());
```

C# / .NET:

```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"
                    }
                } }
            }) }
        }
    })
});
```

Golang:

```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

- `contentHandling`: [ContentHandling](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigatewayv2.ContentHandling.html) — 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.

- `credentialsRole`: [IRole](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — Specifies the credentials role required for the integration.

  **Default:** No credential role provided.

- `integrationMethod`: string (required) — Specifies the integration's HTTP method type.

- `integrationUri`: string (required) — Integration URI.

- `passthroughBehavior`: [PassthroughBehavior](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigatewayv2.PassthroughBehavior.html) — 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.

- `requestParameters`: { [key: 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.

- `requestTemplates`: { [key: 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 }" }
  ```

- `templateSelectionExpression`: string — The template selection expression for the integration.

  **Default:** No template selection expression provided.

- `timeout`: [Duration](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Duration.html) = 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.
