Class WebSocketApi

java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
software.amazon.awscdk.Resource
software.amazon.awscdk.services.apigatewayv2.WebSocketApi
All Implemented Interfaces:
IResource, IApi, IWebSocketApi, software.amazon.jsii.JsiiSerializable, software.constructs.IConstruct, software.constructs.IDependable

@Generated(value="jsii-pacmak/1.94.0 (build b380f01)", date="2024-03-01T20:58:18.524Z") @Stability(Stable) public class WebSocketApi extends Resource implements IWebSocketApi, IApi
Create a new API Gateway WebSocket API endpoint.

Example:

 import software.amazon.awscdk.aws_apigatewayv2_integrations.WebSocketLambdaIntegration;
 Function messageHandler;
 WebSocketApi webSocketApi = new WebSocketApi(this, "mywsapi");
 WebSocketStage.Builder.create(this, "mystage")
         .webSocketApi(webSocketApi)
         .stageName("dev")
         .autoDeploy(true)
         .build();
 webSocketApi.addRoute("sendMessage", WebSocketRouteOptions.builder()
         .integration(new WebSocketLambdaIntegration("SendMessageIntegration", messageHandler))
         .build());
 
  • Constructor Details

    • WebSocketApi

      protected WebSocketApi(software.amazon.jsii.JsiiObjectRef objRef)
    • WebSocketApi

      protected WebSocketApi(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • WebSocketApi

      @Stability(Stable) public WebSocketApi(@NotNull software.constructs.Construct scope, @NotNull String id, @Nullable WebSocketApiProps props)
      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      props -
    • WebSocketApi

      @Stability(Stable) public WebSocketApi(@NotNull software.constructs.Construct scope, @NotNull String id)
      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
  • Method Details

    • fromWebSocketApiAttributes

      @Stability(Stable) @NotNull public static IWebSocketApi fromWebSocketApiAttributes(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull WebSocketApiAttributes attrs)
      Import an existing WebSocket API into this CDK app.

      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      attrs - This parameter is required.
    • addRoute

      @Stability(Stable) @NotNull public WebSocketRoute addRoute(@NotNull String routeKey, @NotNull WebSocketRouteOptions options)
      Add a new route.

      Parameters:
      routeKey - This parameter is required.
      options - This parameter is required.
    • arnForExecuteApi

      @Stability(Stable) @NotNull public String arnForExecuteApi(@Nullable String method, @Nullable String path, @Nullable String stage)
      Get the "execute-api" ARN.

      When 'ANY' is passed to the method, an ARN with the method set to '*' is obtained.

      Default: - The default behavior applies when no specific method, path, or stage is provided. In this case, the ARN will cover all methods, all resources, and all stages of this API. Specifically, if 'method' is not specified, it defaults to '*', representing all methods. If 'path' is not specified, it defaults to '/*', representing all paths. If 'stage' is not specified, it also defaults to '*', representing all stages.

      Parameters:
      method -
      path -
      stage -
    • arnForExecuteApi

      @Stability(Stable) @NotNull public String arnForExecuteApi(@Nullable String method, @Nullable String path)
      Get the "execute-api" ARN.

      When 'ANY' is passed to the method, an ARN with the method set to '*' is obtained.

      Default: - The default behavior applies when no specific method, path, or stage is provided. In this case, the ARN will cover all methods, all resources, and all stages of this API. Specifically, if 'method' is not specified, it defaults to '*', representing all methods. If 'path' is not specified, it defaults to '/*', representing all paths. If 'stage' is not specified, it also defaults to '*', representing all stages.

      Parameters:
      method -
      path -
    • arnForExecuteApi

      @Stability(Stable) @NotNull public String arnForExecuteApi(@Nullable String method)
      Get the "execute-api" ARN.

      When 'ANY' is passed to the method, an ARN with the method set to '*' is obtained.

      Default: - The default behavior applies when no specific method, path, or stage is provided. In this case, the ARN will cover all methods, all resources, and all stages of this API. Specifically, if 'method' is not specified, it defaults to '*', representing all methods. If 'path' is not specified, it defaults to '/*', representing all paths. If 'stage' is not specified, it also defaults to '*', representing all stages.

      Parameters:
      method -
    • arnForExecuteApi

      @Stability(Stable) @NotNull public String arnForExecuteApi()
      Get the "execute-api" ARN.

      When 'ANY' is passed to the method, an ARN with the method set to '*' is obtained.

      Default: - The default behavior applies when no specific method, path, or stage is provided. In this case, the ARN will cover all methods, all resources, and all stages of this API. Specifically, if 'method' is not specified, it defaults to '*', representing all methods. If 'path' is not specified, it defaults to '/*', representing all paths. If 'stage' is not specified, it also defaults to '*', representing all stages.

    • grantManageConnections

      @Stability(Stable) @NotNull public Grant grantManageConnections(@NotNull IGrantable identity)
      Grant access to the API Gateway management API for this WebSocket API to an IAM principal (Role/Group/User).

      Parameters:
      identity - The principal. This parameter is required.
    • metric

      @Stability(Stable) @NotNull public Metric metric(@NotNull String metricName, @Nullable MetricOptions props)
      Return the given named metric for this Api Gateway.

      Specified by:
      metric in interface IApi
      Parameters:
      metricName - This parameter is required.
      props -
    • metric

      @Stability(Stable) @NotNull public Metric metric(@NotNull String metricName)
      Return the given named metric for this Api Gateway.

      Specified by:
      metric in interface IApi
      Parameters:
      metricName - This parameter is required.
    • getApiEndpoint

      @Stability(Stable) @NotNull public String getApiEndpoint()
      The default endpoint for an API.
      Specified by:
      getApiEndpoint in interface IApi
    • getApiId

      @Stability(Stable) @NotNull public String getApiId()
      The identifier of this API Gateway API.
      Specified by:
      getApiId in interface IApi
    • getWebSocketApiName

      @Stability(Stable) @Nullable public String getWebSocketApiName()
      A human friendly name for this WebSocket API.

      Note that this is different from webSocketApiId.