Skip to content

Commit

Permalink
feat(apigatewayv2): add missing WebSocketIntegration props (#29566)
Browse files Browse the repository at this point in the history
### Issue # (if applicable)

None as far as I can tell

### Reason for this change

I was looking at the WebSocket integration to get a feel for #29562, and noticed a couple of missing properties

### Description of changes

* Added support for `timeout` and `contentHandling`
* Minor copy-pasta fixes in documentation and test description

### Description of how you validated changes

I've added unit tests to check these optional properties. I've also updated and verified the following integrations tests:

* `integ.lambda.ts`:
  * `ContentHandlingStrategy` and `TimeoutInMillis` are both correctly set
```sh
$ aws apigatewayv2 get-integration --api-id bu24s9i8t0 --integration-id fxqec8c
{
    "ConnectionType": "INTERNET",
    "ContentHandlingStrategy": "CONVERT_TO_TEXT",
    "IntegrationId": "fxqec8c",
    "IntegrationMethod": "POST",
    "IntegrationType": "AWS_PROXY",
    "IntegrationUri": "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:637423343434:function:WebSocketApiInteg-DefaultHandler604DF7AC-GSQYxsiaKjkz/invocations",
    "PassthroughBehavior": "WHEN_NO_MATCH",
    "PayloadFormatVersion": "1.0",
    "RequestTemplates": {},
    "TimeoutInMillis": 10000
}
```
* `integ.aws.ts`:
  * `ContentHandlingStrategy`, `TemplateSelectionExpression`, `TimeoutInMillis`,  `PassthroughBehavior`, and `RequestParameters` are all correctly set
 
```sh
$ aws apigatewayv2 get-integration --api-id qp17tw07w3 --integration-id hycmjxb
{
    "ConnectionType": "INTERNET",
    "ContentHandlingStrategy": "CONVERT_TO_BINARY",
    "CredentialsArn": "arn:aws:iam::637423343434:role/integ-aws-websocket-integrat-ApiGatewayRoleD2518903-i80lztfxo5XI",
    "IntegrationId": "hycmjxb",
    "IntegrationMethod": "POST",
    "IntegrationResponseSelectionExpression": "${integration.response.statuscode}",
    "IntegrationType": "AWS",
    "IntegrationUri": "arn:aws:apigateway:us-east-1:dynamodb:action/PutItem",
    "PassthroughBehavior": "WHEN_NO_TEMPLATES",
    "PayloadFormatVersion": "1.0",
    "RequestParameters": {
        "integration.request.header.Content-Type": "'application/x-www-form-urlencoded'"
    },
    "RequestTemplates": {
        "application/json": "{\"TableName\":\"MyTable\",\"Item\":{\"id\":{\"S\":\"$context.requestId\"}}}"
    },
    "TemplateSelectionExpression": "\\$default",
    "TimeoutInMillis": 10000
}
```

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
nmussy authored Mar 22, 2024
1 parent 3a78125 commit 7534dcd
Show file tree
Hide file tree
Showing 18 changed files with 358 additions and 184 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"ApiId": {
"Ref": "mywsapi32E6CE11"
},
"ContentHandlingStrategy": "CONVERT_TO_BINARY",
"CredentialsArn": {
"Fn::GetAtt": [
"ApiGatewayRoleD2518903",
Expand All @@ -117,6 +118,10 @@
]
]
},
"PassthroughBehavior": "WHEN_NO_TEMPLATES",
"RequestParameters": {
"integration.request.header.Content-Type": "'application/x-www-form-urlencoded'"
},
"RequestTemplates": {
"application/json": {
"Fn::Join": [
Expand All @@ -130,7 +135,9 @@
]
]
}
}
},
"TemplateSelectionExpression": "\\$default",
"TimeoutInMillis": 10000
}
},
"mywsapiconnectRoute45A0ED6A": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HttpMethod, WebSocketApi, WebSocketStage } from 'aws-cdk-lib/aws-apigatewayv2';
import { ContentHandling, HttpMethod, PassthroughBehavior, WebSocketApi, WebSocketStage } from 'aws-cdk-lib/aws-apigatewayv2';
import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
import * as iam from 'aws-cdk-lib/aws-iam';
import { App, RemovalPolicy, Stack } from 'aws-cdk-lib';
import { App, Duration, RemovalPolicy, Stack } from 'aws-cdk-lib';
import { WebSocketAwsIntegration, WebSocketMockIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations';
import { IntegTest } from '@aws-cdk/integ-tests-alpha';

Expand Down Expand Up @@ -42,6 +42,9 @@ webSocketApi.addRoute('$connect', {
integrationUri: `arn:aws:apigateway:${stack.region}:dynamodb:action/PutItem`,
integrationMethod: HttpMethod.POST,
credentialsRole: apiRole,
requestParameters: {
'integration.request.header.Content-Type': '\'application/x-www-form-urlencoded\'',
},
requestTemplates: {
'application/json': JSON.stringify({
TableName: table.tableName,
Expand All @@ -52,6 +55,10 @@ webSocketApi.addRoute('$connect', {
},
}),
},
templateSelectionExpression: '\\$default',
passthroughBehavior: PassthroughBehavior.WHEN_NO_TEMPLATES,
contentHandling: ContentHandling.CONVERT_TO_BINARY,
timeout: Duration.seconds(10),
}),
});

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@
"ApiId": {
"Ref": "mywsapi32E6CE11"
},
"ContentHandlingStrategy": "CONVERT_TO_TEXT",
"IntegrationType": "AWS_PROXY",
"IntegrationUri": {
"Fn::Join": [
Expand All @@ -454,7 +455,8 @@
"/invocations"
]
]
}
},
"TimeoutInMillis": 10000
}
},
"mywsapidefaultRouteE9382DF8": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7534dcd

Please sign in to comment.