The documentation about apigateway.Resource here: https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-apigateway.Resource.html
has this to say about the parent prop:
parent
Type: IResource
The parent resource of this resource.
You can either pass another Resource object or a RestApi object here.
The last part, in bold, is the problem as it does not seem that a restapi object is being accepted.
const myapi = new apigateway.RestApi(this, 'apigatewayApi');
const resource = new apigateway.Resource(this, 'apigatewayResourceTest', {
parent: myapi,
pathPart: 'test'
});
(removed my local and project paths)
xxx/@aws-cdk/aws-apigateway/lib/resource.js:163
restApiId: props.parent.restApi.restApiId,
^
TypeError: Cannot read property 'restApiId' of undefined
at new Resource (xxx/@aws-cdk/aws-apigateway/lib/resource.js:163:45)
This is :bug: Bug Report
The following gets me past the assembly step, i can add all the constructs, but then it errors out when running synth.
file: node_modules/@aws-sdk/aws-apigateway/lib/resource.js
lines 162-176
(bold bits changed)
const resourceProps = {
restApiId: typeof props.parent.restApi === 'undefined' ? props.parent.restApiId : props.parent.restApi.restApiId,
parentId: props.parent.resourceId,
pathPart: props.pathPart
};
const resource = new apigateway_generated_1.CfnResource(this, 'Resource', resourceProps);
this.resourceId = resource.ref;
this.restApi = typeof props.parent.restApi === 'undefined' ? props.parent : props.parent.restApi;
// render resource path (special case for root)
this.path = typeof props.parent.path === 'undefined' ? '/' : props.parent.path;
if (!this.path.endsWith('/')) {
this.path += '/';
}
this.path += props.pathPart;
const deployment = typeof props.parent.restApi === 'undefined' ? props.parent.latestDeployment : props.parent.restApi.latestDeployment;
(replaced my local path with xxx)
xxx/@aws-cdk/core/lib/resolvable.js:51
throw e;
^
Error: Resolution error: Supplied properties not correct for "CfnResourceProps"
parentId: required but missing.
Object creation stack:
at new Intrinsic (xxx/@aws-cdk/core/lib/private/intrinsic.js:20:44)
at new PostResolveToken (xxx/@aws-cdk/core/lib/util.js:72:9)
at CfnResource._toCloudFormation (xxx/@aws-cdk/core/lib/cfn-resource.js:167:39)
at elements.map.e (xxx/@aws-cdk/core/lib/stack.js:547:60)
at Array.map (
at Fp6Stack._toCloudFormation (xxx/@aws-cdk/core/lib/stack.js:547:36)
at Fp6Stack.synthesize (xxx/@aws-cdk/core/lib/stack.js:500:42)
at Function.synth (xxx/@aws-cdk/core/lib/construct.js:65:27)
at App.synth (xxx/@aws-cdk/core/lib/app.js:71:52)
at process.App.process.once (xxx/@aws-cdk/core/lib/app.js:45:51)
at Object.onceWrapper (events.js:286:20)
at process.emit (events.js:198:13)
at ValidationResult.assertSuccess (xxx/@aws-cdk/core/lib/runtime.js:126:19)
at cfnResourcePropsToCloudFormation (xxx/@aws-cdk/aws-apigateway/lib/apigateway.generated.js:1598:43)
at CfnResource.renderProperties (xxx/@aws-cdk/aws-apigateway/lib/apigateway.generated.js:1637:16)
at PostResolveToken.ret.Resources.util_1.PostResolveToken.props [as processor] (xxx/@aws-cdk/core/lib/cfn-resource.js:178:52)
at PostResolveToken.postProcess (xxx/@aws-cdk/core/lib/util.js:80:21)
at Object.postProcess (xxx/@aws-cdk/core/lib/private/resolve.js:30:82)
at DefaultTokenResolver.resolveToken (xxx/@aws-cdk/core/lib/resolvable.js:42:38)
at resolve (xxx/@aws-cdk/core/lib/private/resolve.js:94:33)
at Object.resolve (xxx/@aws-cdk/core/lib/private/resolve.js:28:33)
at resolve (xxx/@aws-cdk/core/lib/private/resolve.js:111:43)
Subprocess exited with error 1
parent: myapi.root?
You can also use myapi.root.addResource('test') see README.
yes! adding the .root solved it :D thank you!
Solved it for me too, thanks for hitting it before me 👍
Might be worth thinking about updating the documentation, it's misleading here:
parent (IResource) – The parent resource of this resource. You can either pass another Resource object or a RestApi object here.
https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_apigateway/ProxyResource.html
Most helpful comment
parent: myapi.root?You can also use
myapi.root.addResource('test')see README.