(aws-apigateway): Allow other stacks to add resource-paths to existing gateway resource-paths, and update Stage to latest Deployment
See original GitHub issue-
We have a CDK for our ApiGateway which has a base resource-path
/v1
. We have many lambda functions: we want Lambda-cdk’s to add resource paths to existing resource paths, whether they are created by this lambda’s CDK stack, or another lambda’s CDK stack. -
If another Stack creates an Api Deployment, the ApiGateway Stage should point to these new deployments
Use Case
CdkApiGateway
- adds resource path
/v1
- deploy :
true
- stage:
DEV
CdkLambda-1
const apiGateway = apiGateway.RestApi.fromRestApiAttributes(this, `api`, {
restApiId: <restapi id from cf export>,
rootResourceId: <root resource id from cf export>,
});
apiGateway.root.getResource('/v1')
.addResource('lambda1Path')
.addMethod("GET")
CdkLambda-2
const apiGateway = apiGateway.RestApi.fromRestApiAttributes(this, `api`, {
restApiId: <restapi id from cf export>,
rootResourceId: <root resource id from cf export>,
});
apiGateway.root.getResource('/v1')
.getResource('lambda1Path')
.addResource('lambda2Path')
Proposed Solution
A: currently “.getResource()” returns an undefined
object, so we can’t handle existing resources in CDK.
- Should return a defined resource to add resources, or add methods to, AND allow another stack to add resource-paths to the existing resource
B: Currently .resourceForPath("/v1")
throws an error
CREATE_FAILED | AWS::ApiGateway::Resource | api-dev/Default/v1 (apidevv1795DEFC9) Another resource with the same parent already has this name: v1 (Service: AmazonApiGateway; Status Code: 409; Error Code: ConflictException; Request ID: 16d1f261-3a68-4771-98c8-2a6b7398e6d0; Proxy: null)
- Should remove constraint, and allow other stacks to add resources to existing paths.
`.resourceForPath()` should allows us to Get an existing path, or create the path
Other
- 👋 I may be able to implement this feature request
- ⚠️ This feature might incur a breaking change
This is a 🚀 Feature Request
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (2 by maintainers)
Top GitHub Comments
@nija-at I also have this error.
Here is an example that “works” however, the lambda gets the wrong target path:
This approach does create the proper methods in the right spot, however, the lambda target ArnLike is
.../address
instead of the expected full path of.../v1/address
.Let’s say I start at the root (/):
Will fail because the
getResource('/v1')
is undefined. If I change it to havegtwy.root.resourceForPath('/v1')
, the proper target path for the lambda is set, but will not complete with the following error:Another resource with the same parent already has this name
.I understand the idea behind creating another stack, but, we are moving over to CDK and is currently using serverless for the root path. I will attempt to import that from its CF stack, but, seems odd this cannot be done.
Okay, wanted to call out changing the Deployment LogicalId.