Skip to content

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

@JobaDiniz

Description

@JobaDiniz

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

Metadata

Metadata

Assignees

Labels

@aws-cdk/aws-apigatewayv2Related to Amazon API Gateway v2effort/smallSmall work item – less than a day of effortfeature-requestA feature should be added or improved.good first issueRelated to contributions. See CONTRIBUTING.mdp1

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions