Aws-cdk: apigateway.Resource props.parent not accepting RestAPI

Created on 24 Oct 2019  ·  5Comments  ·  Source: aws/aws-cdk

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.

Reproduction Steps

const myapi = new apigateway.RestApi(this, 'apigatewayApi');
const resource = new apigateway.Resource(this, 'apigatewayResourceTest', {
    parent: myapi,
    pathPart: 'test'
});

Error Log

(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)

Environment

  • **CLI Version :aws-cli/1.16.184 Python/3.7.3 Linux/5.0.0-32-generic botocore/1.12.174
  • **Framework Version: CDK 1.14.0
  • **OS : Ubuntu Linux.
  • **Language :english

This is :bug: Bug Report

bug needs-triage

Most helpful comment

parent: myapi.root?

You can also use myapi.root.addResource('test') see README.

All 5 comments

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;

the error:

(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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cybergoof picture cybergoof  ·  3Comments

kawamoto picture kawamoto  ·  3Comments

artyom-melnikov picture artyom-melnikov  ·  3Comments

ababra picture ababra  ·  3Comments

eladb picture eladb  ·  3Comments