Skip to content

(apigatewayv2): property to extract WebSocket control endpoint URL #14836

@adam-nielsen

Description

@adam-nielsen

In Lambda, if you want to send a message to a WebSocket, you have to supply a HTTPS endpoint for the API Gateway control interface. However there appears to be no way to obtain this URL when the WebSocket is created via CDK,

Use Case

I want to create a WebSocket, and have a Lambda function send messages to connected clients in response to non-WebSocket events (e.g. SQS message arrival). This means I can't extract the WebSocket control address from the Lambda event object as it is not a WebSocket message that has triggered the function. Instead I must pass the WebSocket control URL in via some other method such as an environment variable.

Proposed Solution

There is already a WebSocketApi.apiEndpoint property for the WebSocket itself (minus the stage) so I guess it would work better in WebSocketStage having a property like .controlEndpoint.

So far I have worked around the issue by (in CDK) using a constructed string like this:

`https://${webSocketApi.apiId}.execute-api.${this.region}.amazonaws.com/${webSocketStage.stageName}`

But it would be nicer if this was provided by the library.

Other

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

This is a 🚀 Feature Request

Metadata

Metadata

Assignees

No one assigned

    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.mdp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions