class WebSocketApi (construct)
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.APIGatewayv2.WebSocketApi |
Java | software.amazon.awscdk.services.apigatewayv2.WebSocketApi |
Python | aws_cdk.aws_apigatewayv2.WebSocketApi |
TypeScript (source) | @aws-cdk/aws-apigatewayv2 ยป WebSocketApi |
Implements
IConstruct
, IConstruct
, IDependable
, IResource
, IWeb
, IApi
Create a new API Gateway WebSocket API endpoint.
Example
import { WebSocketLambdaIntegration } from '@aws-cdk/aws-apigatewayv2-integrations';
declare const messageHandler: lambda.Function;
const webSocketApi = new apigwv2.WebSocketApi(this, 'mywsapi');
webSocketApi.addRoute('sendmessage', {
integration: new WebSocketLambdaIntegration('SendMessageIntegration', messageHandler),
});
Initializer
new WebSocketApi(scope: Construct, id: string, props?: WebSocketApiProps)
Parameters
- scope
Construct
- id
string
- props
Web
Socket Api Props
Construct Props
Name | Type | Description |
---|---|---|
api | Web | An API key selection expression. |
api | string | Name for the WebSocket API resource. |
connect | Web | Options to configure a '$connect' route. |
default | Web | Options to configure a '$default' route. |
description? | string | The description of the API. |
disconnect | Web | Options to configure a '$disconnect' route. |
route | string | The route selection expression for the API. |
apiKeySelectionExpression?
Type:
Web
(optional, default: Key is not required to access these APIs)
An API key selection expression.
Providing this option will require an API Key be provided to access the API.
apiName?
Type:
string
(optional, default: id of the WebSocketApi construct.)
Name for the WebSocket API resource.
connectRouteOptions?
Type:
Web
(optional, default: no '$connect' route configured)
Options to configure a '$connect' route.
defaultRouteOptions?
Type:
Web
(optional, default: no '$default' route configured)
Options to configure a '$default' route.
description?
Type:
string
(optional, default: none)
The description of the API.
disconnectRouteOptions?
Type:
Web
(optional, default: no '$disconnect' route configured)
Options to configure a '$disconnect' route.
routeSelectionExpression?
Type:
string
(optional, default: '$request.body.action')
The route selection expression for the API.
Properties
Name | Type | Description |
---|---|---|
api | string | The default endpoint for an API. |
api | string | The identifier of this API Gateway API. |
env | Resource | The environment this resource belongs to. |
node | Construct | The construct tree node associated with this construct. |
stack | Stack | The stack in which this resource is defined. |
web | string | A human friendly name for this WebSocket API. |
apiEndpoint
Type:
string
The default endpoint for an API.
apiId
Type:
string
The identifier of this API Gateway API.
env
Type:
Resource
The environment this resource belongs to.
For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.
node
Type:
Construct
The construct tree node associated with this construct.
stack
Type:
Stack
The stack in which this resource is defined.
webSocketApiName?
Type:
string
(optional)
A human friendly name for this WebSocket API.
Note that this is different from webSocketApiId
.
Methods
Name | Description |
---|---|
add | Add a new route. |
apply | Apply the given removal policy to this resource. |
grant | Grant access to the API Gateway management API for this WebSocket API to an IAM principal (Role/Group/User). |
metric(metricName, props?) | Return the given named metric for this Api Gateway. |
to | Returns a string representation of this construct. |
static from | Import an existing WebSocket API into this CDK app. |
Route(routeKey, options)
addpublic addRoute(routeKey: string, options: WebSocketRouteOptions): WebSocketRoute
Parameters
- routeKey
string
- options
Web
Socket Route Options
Returns
Add a new route.
RemovalPolicy(policy)
applypublic applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
Apply the given removal policy to this resource.
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.
The resource can be deleted (RemovalPolicy.DESTROY
), or left in your AWS
account for data recovery and cleanup later (RemovalPolicy.RETAIN
).
ManageConnections(identity)
grantpublic grantManageConnections(identity: IGrantable): Grant
Parameters
- identity
IGrantable
โ The principal.
Returns
Grant access to the API Gateway management API for this WebSocket API to an IAM principal (Role/Group/User).
metric(metricName, props?)
public metric(metricName: string, props?: MetricOptions): Metric
Parameters
- metricName
string
- props
Metric
Options
Returns
Return the given named metric for this Api Gateway.
String()
topublic toString(): string
Returns
string
Returns a string representation of this construct.
WebSocketApiAttributes(scope, id, attrs)
static frompublic static fromWebSocketApiAttributes(scope: Construct, id: string, attrs: WebSocketApiAttributes): IWebSocketApi
Parameters
- scope
Construct
- id
string
- attrs
Web
Socket Api Attributes
Returns
Import an existing WebSocket API into this CDK app.