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

(apigateway): Imported RestAPIs do not have access to its methods due to casting #26247

Open
peterwoodworth opened this issue Jul 5, 2023 · 0 comments
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway bug This issue is a bug. effort/small Small work item – less than a day of effort p2

Comments

@peterwoodworth
Copy link
Contributor

Describe the bug

Imported RestAPIs are returned by CDK as IRestAPI. However in the source code, the imports extend RestAPIBase which features additional helpful methods, such as the metric methods. The IRestAPI interface does not come with methods such as the metric methods, which prevents methods from being called without casting the imported RestAPI as a RestAPIBase.

Expected Behavior

I expect to be able to use methods that are okay to use on an imported RestAPI.

Current Behavior

I cannot use some methods that I should be able to

Reproduction Steps

You can successfully call the method using the following code. Note that removing the typecasting causes this to fail

export class TestingStack extends cdk.Stack {
  public restApi: apigw.RestApiBase;
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    this.restApi = apigw.RestApi.fromRestApiId(this,"MyGatewayApi","restApiId") as apigw.RestApiBase;
    
    const api = new cw.Alarm(this, `api-error-alarm`, {
      alarmName: 'api-error-alarm',
      threshold: 5,
      evaluationPeriods: 1,
      metric: this.restApi.metricServerError()
    });
  }
}

Possible Solution

Probably put these methods on IRestAPI interface, but I didn't dive too deep into this so that could have other side effects.

Additional Information/Context

No response

CDK CLI Version

latest

Framework Version

No response

Node.js Version

16

OS

mac

Language

Typescript

Language Version

No response

Other information

Sourced from this discussion

@peterwoodworth peterwoodworth added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 5, 2023
@github-actions github-actions bot added the @aws-cdk/aws-apigateway Related to Amazon API Gateway label Jul 5, 2023
@peterwoodworth peterwoodworth added p2 effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway bug This issue is a bug. effort/small Small work item – less than a day of effort p2
Projects
None yet
1 participant