-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(apigatewayv2): websocket api (#13031)
feat(apigatewayv2): add support for WebSocket APIs BREAKING CHANGE: `HttpApiMapping` (and related interfaces for `Attributed` and `Props`) has been renamed to `ApiMapping` * **apigatewayv2:** `CommonStageOptions` has been renamed to `StageOptions` * **apigatewayv2:** `HttpStage.fromStageName` has been removed in favour of `HttpStage.fromHttpStageAttributes` * **apigatewayv2:** `DefaultDomainMappingOptions` has been removed in favour of `DomainMappingOptions` * **apigatewayv2:** `HttpApiProps.defaultDomainMapping` has been changed from `DefaultDomainMappingOptions` to `DomainMappingOptions` * **apigatewayv2:** `HttpApi.defaultStage` has been changed from `HttpStage` to `IStage` * **apigatewayv2:** `IHttpApi.defaultStage` has been removed closes #2872 Some notes: 1. Only Lambda Integration is currently supported 2. No support for `IntegrationResponse` and `RouteResponse`. 3. The `$default` stageName does not seem to work for WebSocket APIs. Therefore modified the API for defaultStage in the API. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
1 parent
8e612ca
commit fe1c839
Showing
32 changed files
with
1,904 additions
and
380 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './http'; | ||
export * from './websocket'; |
1 change: 1 addition & 0 deletions
1
packages/@aws-cdk/aws-apigatewayv2-integrations/lib/websocket/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './lambda'; |
44 changes: 44 additions & 0 deletions
44
packages/@aws-cdk/aws-apigatewayv2-integrations/lib/websocket/lambda.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { | ||
IWebSocketRouteIntegration, | ||
WebSocketIntegrationType, | ||
WebSocketRouteIntegrationBindOptions, | ||
WebSocketRouteIntegrationConfig, | ||
} from '@aws-cdk/aws-apigatewayv2'; | ||
import { ServicePrincipal } from '@aws-cdk/aws-iam'; | ||
import { IFunction } from '@aws-cdk/aws-lambda'; | ||
import { Names, Stack } from '@aws-cdk/core'; | ||
|
||
/** | ||
* Lambda WebSocket Integration props | ||
*/ | ||
export interface LambdaWebSocketIntegrationProps { | ||
/** | ||
* The handler for this integration. | ||
*/ | ||
readonly handler: IFunction | ||
} | ||
|
||
/** | ||
* Lambda WebSocket Integration | ||
*/ | ||
export class LambdaWebSocketIntegration implements IWebSocketRouteIntegration { | ||
constructor(private props: LambdaWebSocketIntegrationProps) {} | ||
|
||
bind(options: WebSocketRouteIntegrationBindOptions): WebSocketRouteIntegrationConfig { | ||
const route = options.route; | ||
this.props.handler.addPermission(`${Names.nodeUniqueId(route.node)}-Permission`, { | ||
scope: options.scope, | ||
principal: new ServicePrincipal('apigateway.amazonaws.com'), | ||
sourceArn: Stack.of(route).formatArn({ | ||
service: 'execute-api', | ||
resource: route.webSocketApi.apiId, | ||
resourceName: `*/*${route.routeKey}`, | ||
}), | ||
}); | ||
|
||
return { | ||
type: WebSocketIntegrationType.AWS_PROXY, | ||
uri: this.props.handler.functionArn, | ||
}; | ||
} | ||
} |
Oops, something went wrong.