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

(apigatewayv2): Change defaultStage to an IHttpStage #14787

Closed
hffmnn opened this issue May 20, 2021 · 6 comments · Fixed by #15607
Closed

(apigatewayv2): Change defaultStage to an IHttpStage #14787

hffmnn opened this issue May 20, 2021 · 6 comments · Fixed by #15607
Labels
@aws-cdk/aws-apigatewayv2 Related to Amazon API Gateway v2 bug This issue is a bug. effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p2

Comments

@hffmnn
Copy link

hffmnn commented May 20, 2021

❓ General Issue

The Question

Via #14541 the metricXXX method moved from IStage to IHttpStage. The defaultStage of a HttpApi returns a IStage, so the methods are not available.

Question: How to access the methods of the default stage?

Environment

  • CDK CLI Version:
  • Module Version: > 1.103.0
  • Node.js Version: v12.19.0
  • OS: macOS BigSur
  • Language (Version): TypeScript (4.2.4)

Other information

When casting api.defaultStage! as IHttpStage; and calling the metricXXX methods generate the expected code, so I guess the defaultStage could return IHttpStage directly?

@hffmnn hffmnn added guidance Question that needs advice or information. needs-triage This issue or PR still needs to be triaged. labels May 20, 2021
@github-actions github-actions bot added the @aws-cdk/aws-apigatewayv2 Related to Amazon API Gateway v2 label May 20, 2021
@peterwoodworth
Copy link
Contributor

peterwoodworth commented Jun 17, 2021

I don't think there's currently any way to access the methodXXX functions on property defaultStage when using an HttpApi.

Edit: You can cast the default stage as an IHttpStage to use the methodXXX functions like so:

const httpApi = new apigw.HttpApi(this, "MyHttpApi")
let defaultStage = httpApi.defaultStage as apigw.IHttpStage;
defaultStage.metricCount()

This is where the CDK creates the default HttpStage.

if (props?.createDefaultStage === undefined || props.createDefaultStage === true) {
this.defaultStage = new HttpStage(this, 'DefaultStage', {
httpApi: this,
autoDeploy: true,
domainMapping: props?.defaultDomainMapping,
});

However, since the property is declared as an IStage

public readonly defaultStage: IStage | undefined;
that is the only part of the HttpStage which prevents you from being able to access the methods.

I don't see why the property can't directly return the IHttpStage, @nija-at was it intentional to remove the methods here? Seems like the change was only related to the WebSocket

@peterwoodworth peterwoodworth removed the needs-triage This issue or PR still needs to be triaged. label Jun 17, 2021
@peterwoodworth
Copy link
Contributor

I'll be closing this now because the workaround I posted above is pretty simple. If anyone would like to revisit changing the defaultStage prop to an IHttpStage ping me and let me know 😄

@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@hffmnn
Copy link
Author

hffmnn commented Jun 18, 2021

@peterwoodworth Personally I would not close it and label it as good first issue instead. There is a workaround (and I described your workaround already in the initial issue description) but still, it is an issue of an imprecise type.

@peterwoodworth peterwoodworth added feature-request A feature should be added or improved. feature/enhancement A new API to make things easier or more intuitive. A catch-all for general feature requests. p2 effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md and removed guidance Question that needs advice or information. labels Jun 18, 2021
@peterwoodworth
Copy link
Contributor

you're right, relabeled as a feature request

@peterwoodworth peterwoodworth removed their assignment Jun 24, 2021
@peterwoodworth peterwoodworth changed the title (apigatewayv2): metricXXX methods for defaultStage (apigatewayv2): Change defaultStage to an IHttpStage Jun 24, 2021
@nija-at nija-at added bug This issue is a bug. and removed feature-request A feature should be added or improved. feature/enhancement A new API to make things easier or more intuitive. A catch-all for general feature requests. labels Jul 16, 2021
@mergify mergify bot closed this as completed in #15607 Sep 3, 2021
mergify bot pushed a commit that referenced this issue Sep 3, 2021
…le without casting it to `IHttpStage` (#15607)

----

Closes #14787. Changes the defaultStage to an IHttpStage.

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

github-actions bot commented Sep 3, 2021

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this issue Sep 6, 2021
…le without casting it to `IHttpStage` (aws#15607)

----

Closes aws#14787. Changes the defaultStage to an IHttpStage.

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
david-doyle-as24 pushed a commit to david-doyle-as24/aws-cdk that referenced this issue Sep 7, 2021
…le without casting it to `IHttpStage` (aws#15607)

----

Closes aws#14787. Changes the defaultStage to an IHttpStage.

*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 bug This issue is a bug. effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants