Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(apigatewayv2): websocket api #13031

Merged
merged 15 commits into from Mar 5, 2021
Merged

feat(apigatewayv2): websocket api #13031

merged 15 commits into from Mar 5, 2021

Conversation

ayush987goyal
Copy link
Contributor

@ayush987goyal ayush987goyal commented Feb 13, 2021

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

@gitpod-io
Copy link

gitpod-io bot commented Feb 13, 2021

@github-actions github-actions bot added the @aws-cdk/aws-apigatewayv2 Related to Amazon API Gateway v2 label Feb 13, 2021
@nija-at nija-at changed the title feat(apigatewayv2): add support for WebSocket APIs feat(apigatewayv2): websocket apis Feb 16, 2021
@nija-at nija-at changed the title feat(apigatewayv2): websocket apis feat(apigatewayv2): websocket api Feb 16, 2021
Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome. Thanks for submitting this PR @ayush987goyal.

Some very early feedback. Happy to discuss some of these over chat or on a call, if you prefer.

packages/@aws-cdk/aws-apigatewayv2/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-apigatewayv2/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-apigatewayv2/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-apigatewayv2/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-apigatewayv2/lib/websocket/api.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-apigatewayv2/lib/websocket/api.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-apigatewayv2/lib/websocket/stage.ts Outdated Show resolved Hide resolved
@ayush987goyal
Copy link
Contributor Author

@nija-at I have tried to address most of the comments and taken into account pointers from our discussion. The PR has a lot more number of files now but I believe that will probably be well worth it in the long run.

@ayush987goyal
Copy link
Contributor Author

A couple of extra things to note here are these lint errors which I had to exclude but couldn't find proper way to address. Would love some inputs on them.

error: [awslint:construct-interface-extends-iconstruct:@aws-cdk/aws-apigatewayv2.IHttpApi] construct interface must extend core.IConstruct 
error: [awslint:construct-interface-extends-iconstruct:@aws-cdk/aws-apigatewayv2.IWebSocketApi] construct interface must extend core.IConstruct 

error: [awslint:resource-interface-extends-resource:@aws-cdk/aws-apigatewayv2.IHttpApi] construct interfaces of AWS resources must extend cdk.IResource
error: [awslint:resource-interface-extends-resource:@aws-cdk/aws-apigatewayv2.IWebSocketApi] construct interfaces of AWS resources must extend cdk.IResource

Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reviewed the refactors and given the websocket constructs a quick review, but have not yet reviewed the integration classes and module.

These comments should hopefully give you some directions.

This PR will require a few iterations to get right, so please bear with me.


Some experimental interfaces are renamed

You will need to document all of the breaking changes individually, unfortunately. And it will have to be in this particular format - https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md#step-4-commit. This is because we use conventional commits to parse commit messages and generate our CHANGELOG.

It's fine if you wait until all the major review iterations are done before fixing this up.

packages/@aws-cdk/aws-apigatewayv2/lib/common/api.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-apigatewayv2/lib/common/api.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-apigatewayv2/lib/common/stage.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-apigatewayv2/lib/common/api.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-apigatewayv2/lib/common/stage.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-apigatewayv2/lib/http/integration.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-apigatewayv2/lib/common/api.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-apigatewayv2/lib/http/stage.ts Outdated Show resolved Hide resolved
@mergify mergify bot dismissed nija-at’s stale review February 27, 2021 06:19

Pull request has been modified.

nija-at
nija-at previously requested changes Mar 3, 2021
Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fantastic!
Just 1 or 2 comments around the design/refactor, the rest are just small improvements and clarifications.

packages/@aws-cdk/aws-apigatewayv2/lib/common/stage.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-apigatewayv2/lib/common/stage.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-apigatewayv2/lib/websocket/api.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-apigatewayv2/lib/websocket/api.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-apigatewayv2/package.json Outdated Show resolved Hide resolved
@mergify mergify bot dismissed nija-at’s stale review March 3, 2021 11:17

Pull request has been modified.

nija-at
nija-at previously requested changes Mar 4, 2021
Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one comment. This is close to being shipped.

Can we capture the final set of breaking changes per my comment here - #13031 (review)
For class name changes, just capturing them as a single change is sufficient, but we should capture most if not all property changes in existing classes.

I've found jsii-diff helps to produce this. You should be able to run npx jsii-diff npm: and see the relevant output.

Comment on lines +86 to +97
let stage = props.stage;
if (!stage) {
if (props.api instanceof HttpApi) {
if (props.api.defaultStage) {
stage = props.api.defaultStage;
} else {
throw new Error('stage is required if default stage is not available');
}
} else {
throw new Error('stage is required for WebSocket API');
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it cleaner to make props.stage mandatory and drop props.api?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the api prop would still be required since currently api is not available on IStage since we moved it to subclass IHttpStage and IWebSocketStage. Now given that, we can keep this implementation because it provided convenience for HttpApi users (though agree this is not the cleanest of solutions but maybe in future it can be clear when we have defaultStage for WS apis as well). Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So now we can go from IHttpStage -> IHttpApi but can't go from IStage -> IApi? Whoops.
I think we should somehow get both but let's not try to solve this now in this PR.

Leave it as such.

This was referenced Mar 8, 2021
cornerwings pushed a commit to cornerwings/aws-cdk that referenced this pull request Mar 8, 2021
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 aws#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*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-apigatewayv2 Related to Amazon API Gateway v2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[apigateway] L2 Construct for Api Gateway V2 (WebSocket)
3 participants