Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(APIGatewayv2.websocket: add support for HTTP integration #29562

Open
2 tasks
Labels
@aws-cdk/aws-apigatewayv2 Related to Amazon API Gateway v2 feature-request A feature should be added or improved. p2

Comments

@cloudshiftchris
Copy link

Describe the feature

Presently the WebSocketApi construct supports lambda, AWS and Mock integrations; add support for HTTP integration; effectively all available options in the GUI/CFN for this (proxy, vpc link, etc).

Use Case

Websocket messages being delivered to internal HTTP endpoints.

Proposed Solution

Add a new WebSocketHttpIntegration implementation of WebSocketIntegration

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.132.0

Environment details (OS name and version, etc.)

MacOS

@cloudshiftchris cloudshiftchris added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Mar 20, 2024
@github-actions github-actions bot added the @aws-cdk/aws-apigatewayv2 Related to Amazon API Gateway v2 label Mar 20, 2024
@nmussy
Copy link
Contributor

nmussy commented Mar 20, 2024

Associated documentation/API:

Current CDK implementation:

Both WebSocketIntegrationType.HTTP and WebSocketIntegrationType.HTTP_PROXY are currently missing, as well as their associated WebSocketRouteIntegration implementations

@pahud
Copy link
Contributor

pahud commented Mar 21, 2024

@cloudshiftchris Thank you for the report.

@nmussy Thank you for your PR! This is awesome!

@pahud pahud added p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Mar 21, 2024
@nmussy
Copy link
Contributor

nmussy commented Mar 21, 2024

The PR I've opened doesn't address this specific issue, but will add properties that are also used by the HTTP integrations. I'll take care of them later if no one else takes them on 👍

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Mar 21, 2024
mergify bot pushed a commit that referenced this issue Mar 22, 2024
### 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*
ahammond pushed a commit to ahammond/aws-cdk that referenced this issue Mar 26, 2024
### 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 aws#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*
@nmussy
Copy link
Contributor

nmussy commented Mar 29, 2024

Progress report: I got things mostly figured out for the HTTP integrations. One thing I did notice was the lack of proper support for CfnIntegrationResponse, which is essential if you want to receive the response of an HTTP integration. So I'm going to open another PR to implement them as well, wait for that to be merged, and then #29589 should be good to go 👍

@nmussy
Copy link
Contributor

nmussy commented Apr 24, 2024

Just as an FYI, I haven't forgotten about this issue. The PR was closed for inactivity, but I'm waiting for #29661 to be reviewed and merged so I can finalize the integ tests for #29589

@dtczest
Copy link

dtczest commented May 15, 2024

Just +1ing this issue. Thanks for the work on this.

@zscgeek
Copy link

zscgeek commented Jul 27, 2024

Watching - this would be a huge help for me.

@alpinisme
Copy link

Has anyone managed to achieve this even with an L1 construct? We're looking to do an http integration at my work as well.

@mjshea-ryoma
Copy link

+1 as well. This is a pretty significant gap in CDK feature parity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-apigatewayv2 Related to Amazon API Gateway v2 feature-request A feature should be added or improved. p2
Projects
None yet
7 participants