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] ability to add methods and resources to an imported RestApi #1477
Comments
You should be able to use the export/import mechanism
|
So I just tried this approach this morning and this is the error that I receive.
I was looking through the source code and I see that they do not exist in the ImportedRestApi class, only in the RestAPI class. Is this by design? If so, I'm assuming this means that it's a readonly state so I can't continue to add routes from another stack? Or is this portion incomplete? Just seems to be an inconvenience, not really with the CDK but more with CloudFormation's limit of 200 resources. |
Thanks for trying, I'll classify this as a bug for now until we can get around to fixing it. |
@tjsteinhaus indeed it is currently impossible to modify the model of a RestApi resource that was defined in another stack. This is why I am wondering, though, how did the typescript compiler let you use the |
@eladb I'm not using Typescript but just good ol' plain Javascript. But I can show you an abbreviated version of what we're doing. Stack 2
Stack 6
MyApp CDK Main Class
Stack 6 is where we are trying to extend the api gateway instead of creating a new one. |
This feature would be really useful for me as well. I'm basically trying to use the same API Gateway for multiple microservices. |
Does this have a release date already? |
+1 |
Did anyone of you mange to split the API Gateway resources into different stacks? So far I was only able to put Furthermore I faced a big problem regarding the I really have to say that the most annoying thing of working with aws cdk are the resource limitations of AWS CloudFormation (e.g. 200 resource max in one stack and 60 parameters max in one stack). It cost so much time to work around such limitations... I'd highly appreciate if someone could bring some light in the darkness. Maybe I'm missing something here... |
We're having the same issue here @Poweranimal. I think the best solution would be having one api-gateway in each stack together with the lambdas. Then if you have a custom domain map it to all the separated api-gateways. |
@AlexRex I also have this issue, Like above, we have a large amount of lambdas that are related to a given api gateway, I have successfully split the lambdas into multiple stacks separate to the gateway, but am unable to figure out a way to split the gateway resources into separate stacks. I am concerned about scaling my API to be larger will hit the limit of the gateway stack, Any solutions for that? |
Having the same issue here, Getting the 200 resources limit so I've tried to split it into 2 stacks, no luck so far. |
Edit: I've just realised that this might not correspond to the problem mentioned at the beginning. This will only help if the API Gateway resources alone does not exceed the 200 limit. If it does, then the solution by @AlexRex is the best one for now. This is how we are doing it right now. We basically have multiple stack that share the same API Gateway class (RestApi) class MultipleStackConstruct extends Construct {
constructor(scope: Construct, id: string) {
super(scope, id);
// Main stack with shared components
const commonStack = new CommonStack(
scope,
`common-stack`
);
// Module 1
const moduleOneStack = new ModulOneStack(
scope,
`module-one`,
{
apiGatewayRestApi: commonStack.apiGatewayRestApi
}
);
// Module 2, 3, etc.....
}
} This interface is used to pass the props to module stack: export interface CommonProps extends cdk.StackProps {
apiGatewayRestApi: apigw.RestApi;
} The common module will create the API Gateway object: export class CommonStack extends cdk.Stack {
public readonly apiGatewayRestApi: apigw.RestApi;
constructor(scope: cdk.Construct, id: string, props?: CommonProps) {
super(scope, id, props);
/******** SETUP API ********/
this.apiGatewayRestApi = new apigw.RestApi(this, "MyAPI", {
// Options here
});
} So the module stack itself will be something like this: export class ModuleOneStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: CommonProps) {
super(scope, id, props);
if (props && props.apiGatewayRestApi) {
const apiGatewayRestApi = props.apiGatewayRestApi;
// associate lambda with api gateway
}
}
} In this case, we are using only one API Gateway with multiple Lambdas that are divided into multiple stack, because we've also encountered the limit problem. There is a documentation from AWS that is doing the same thing using VPC: |
Hi,
This makes it quite easy to reach the limit with no way of decoupling the API from the stacks where the methods / resources / models / lambda invoke permissions are declared. |
We are looking for the ability to deploy API Gateways & their resources as separate stacks. Currently, the We've tried using CfnMethod & CfnResource and are able to get it to work, but as stated in the comment above, it defeats the point of using CDK as lines as simple as:
turns into:
Forcing the use of imports/exports to pass root resource id & api gateway id. This allow disallows you to utilize |
+1 on this, is there any update on it? |
I had same issue and since there is no answer, I'm posting my temporarily solution. In short I'm recreating minimal context for When using nested stacks pass parameters by calling Code for making:
|
+1 Is there any progress on this issue? We're currently struggling with this issue as well. We've got several APIs relying on relatively large payload models, each of which is heavily documented to provide a comprehensive Swagger experience. Of course, every documentation part is counted towards the resource limit, so a limit of 200 resources is easy to exceed. Without the means to use an imported |
+1 Any updates on this? |
+1, would really love to have this feature. Putting everything in one stack is not ideal. and no great workarounds |
The apigateway CDK construct library creates a large number of CloudFormation resources. To define a single Method that is backed with a Lambda function and authorizer with an Authorizer, ~8 CloudFormation resources are created. This quickly grows and a reasonable sized RestApi is bound to hit the 200 resource limit on their stack. Re-organizing the CDK app into multiple `Stack`s that share the same instance of `RestApi` will not resolve this problem, since the CDK still makes an executive decision to keep the Methods and Resources in the same stack as the `RestApi` construct. (see #7391) This change introduces a new import style API `fromRestApiAttributes()` that returns an instance of `IRestApi` that allows for new Resources to be defined across stacks. As a nice side effect, this change also adds the ability to define Resources on SpecRestApi in addition to what has already been defined in the OpenAPI spec. closes #1477
The apigateway CDK construct library creates a large number of CloudFormation resources. To define a single Method that is backed with a Lambda function and authorizer with an Authorizer, ~8 CloudFormation resources are created. This quickly grows and a reasonable sized RestApi is bound to hit the 200 resource limit on their stack. Re-organizing the CDK app into multiple `Stack`s that share the same instance of `RestApi` will not resolve this problem, since the CDK still makes an executive decision to keep the Methods and Resources in the same stack as the `RestApi` construct. (see #7391) This change introduces a new import style API `fromRestApiAttributes()` that returns an instance of `IRestApi` that allows for new Resources to be defined across stacks. As a nice side effect, this change also adds the ability to define Resources on SpecRestApi in addition to what has already been defined in the OpenAPI spec. closes #1477
+1 |
The apigateway CDK construct library creates a large number of CloudFormation resources. To define a single Method that is backed with a Lambda function and authorizer with an Authorizer, ~8 CloudFormation resources are created. This quickly grows and a reasonable sized RestApi is bound to hit the 200 resource limit on their stack. Re-organizing the CDK app into multiple `Stack`s that share the same instance of `RestApi` will not resolve this problem, since the CDK still makes an executive decision to keep the Methods and Resources in the same stack as the `RestApi` construct. (see #7391) This change introduces a new import style API `fromRestApiAttributes()` that returns an instance of `IRestApi` that allows for new Resources to be defined across stacks. As a nice side effect, this change also adds the ability to define Resources on SpecRestApi in addition to what has already been defined in the OpenAPI spec. closes #1477 closes #7391 fixes #8347 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
+1 Would love the feature to add resources/methods to an existing api gateway stack. |
Edit : Note : |
Another note is that this stack splitting currently works for adding root level resources. Ex: /books and /authors For example it wouldn't be possible to add a 'reviews' nested stack such as /books/{id}/reviews |
AWS CloudFormation now supports increased limits on five service quotas - template size, resources, parameters, mappings, and outputs. The new per template limits for the maximum number of resources is 500 (previously 200) |
Despite the possibility to increase the Cloudformation resource limit, I still would like to split my Rest API Methods over multiple stacks. I believe this is still not possible? |
Huge problem for CDK projects with more than a few API endpoints that include documentation. What's the latest on this? |
I currently have a Stack for both my Lambda's and API Gateway methods, but I'm now hitting my resource limit. By creating a new Stack I currently don't see the ability to access/use an existing api gateway, but instead it creates a new api instead.
Is there a way to access these gateways from other stacks?
The text was updated successfully, but these errors were encountered: