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

Amazon.CDK.AWS.Apigatewayv2.Alpha: Support "AWS" as the IntegrationType for WebSockets #27164

Closed
1 of 2 tasks
JobaDiniz opened this issue Sep 15, 2023 · 3 comments · Fixed by #28718
Closed
1 of 2 tasks
Assignees
Labels
@aws-cdk/aws-apigatewayv2 Related to Amazon API Gateway v2 effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. good first issue Related to contributions. See CONTRIBUTING.md p1

Comments

@JobaDiniz
Copy link

JobaDiniz commented Sep 15, 2023

Describe the feature

Currently, Amazon.CDK.AWS.Apigatewayv2.Alpha lacks support for AWS option as the IntegrationType for WebSocket Apigateway.

The quote from the documentation:

AWS: for integrating the route or method request with an AWS service action, including the Lambda function-invoking action. With the Lambda function-invoking action, this is referred to as the Lambda custom integration. With any other AWS service action, this is known as AWS integration. Supported only for WebSocket APIs.

The important part is:

With any other AWS service action, this is known as AWS integration. Supported only for WebSocket APIs.

That is, you can create a WebSocket Apigateway that calls directly other AWS services without a Lambda function middleware.

Use Case

Ability to create a CDK for WebSocket Apigateway where I can define a direct integration to another AWS service.

For example, WebSocket route integration that triggers a AWS Step Function directly.

This use case is supported using CloudFormation and SAM as follows:

  ApiAuthenticateRouteIntegration:
    Type: AWS::ApiGatewayV2::Integration
    Properties:
      ApiId: !Ref BrokerRobotSocketApi
      IntegrationType: AWS
      IntegrationMethod: POST
      IntegrationUri: !Sub "arn:aws:apigateway:${AWS::Region}:states:action/StartExecution"
      CredentialsArn: !Sub "${ApiAuthenticateIntegrationStateMachineExecutionRole.Arn}" 
      TemplateSelectionExpression: \$default
      RequestTemplates: # see: https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api-mapping-template-reference.html
        "$default" : 
          Fn::Sub: >
            #set($statesInput=$util.escapeJavaScript($input.json('$.data')).replaceAll("\\'","'"))
            { 
              "input": "{\"data\":$statesInput, \"metadata\": {\"requestId\":\"$context.requestId\",\"connectionId\":\"$context.connectionId\",\"domainName\":\"$context.domainName\",\"stage\":\"$context.stage\"}}",
              "stateMachineArn": "${BrokerAuthenticatorStateMachine}"
            }

Proposed Solution

From dotnet world, the solution requires the creation of another class that inherits from WebSocketRouteIntegration to expose the specific props needed for IntegrationType as AWS.

I propose a class named WebSocketAwsIntegration, following the convention for the other integrations types already implemented: WebSocketMockIntegration, WebSocketLambdaIntegration.

Alternatively, we could be even more specific and create classes such as WebSocketStepFunctionIntegration, however, this would require considerably more work because we would need to create several classes for every AWS service that is supported with this construct.

In any case, this would require the following changes - looking briefly at the code:

WebSocketRouteIntegrationConfig

Adding the following missing properties: IntegrationMethod, RequestTemplates, CredentialsArn, TemplateSelectionExpression, and probably others depending on the AWS service you want to integrate.

WebSocketIntegrationType

Adding the following option to the enum: AWS.

Other Information

No response

Acknowledgements

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

CDK version used

v2

Environment details (OS name and version, etc.)

Windows 11

@JobaDiniz JobaDiniz added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Sep 15, 2023
@github-actions github-actions bot added the @aws-cdk/aws-apigatewayv2 Related to Amazon API Gateway v2 label Sep 15, 2023
@peterwoodworth peterwoodworth added good first issue Related to contributions. See CONTRIBUTING.md p1 effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Sep 15, 2023
@peterwoodworth
Copy link
Contributor

Thanks for the detailed feature request! I think the solution you proposed makes a lot of sense. If you or anyone else would like to contribute, please see the contributing guide and we'd be happy to review a PR. Else, we will probably address this when we work on graduating these modules to stable, and I'm not sure what the timeframe on that is exactly.

@GavinZZ
Copy link
Contributor

GavinZZ commented Jan 15, 2024

Added a draft to add support for AWS type websocket API integration. Decided to add a generic WebSocketAwsIntegration that can be used across different AWS resources.

@mergify mergify bot closed this as completed in #28718 Jan 18, 2024
mergify bot pushed a commit that referenced this issue Jan 18, 2024
…28718)

Currently, Amazon.CDK.AWS.Apigatewayv2 lacks support for AWS option as the [IntegrationType](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-integration.html#cfn-apigatewayv2-integration-integrationtype) for WebSocket Apigateway.

Added the capability that allows user to create a WebSocket Apigateway that calls directly other AWS services without a Lambda function middleware.

Closes #27164.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

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 effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. good first issue Related to contributions. See CONTRIBUTING.md p1
Projects
None yet
3 participants