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

aws-cdk-lib: NestedStack reference of CustomResource with Fn results in "id.replace is not a function" #30130

Open
hakenmt opened this issue May 9, 2024 · 1 comment
Labels
aws-cdk-lib Related to the aws-cdk-lib package bug This issue is a bug. effort/medium Medium work item – several days of effort investigating This issue is being investigated and/or work is in progress to resolve the issue. p2

Comments

@hakenmt
Copy link

hakenmt commented May 9, 2024

Describe the bug

When I pass a custom resource to a nested stack via props, and then use getAttString() on the custom resource with an input of something like Fn.ref(AWS::Region), when I call app.synth(), I get TypeError: id.replace is not a function.

Expected Behavior

I expect this to work as it does when the custom resource is created in the nested stack. This error does not occur if the custom resource is not passed across stacks via props.

Current Behavior

TypeError: id.replace is not a function

   9 |     const stack = new BugStack(app, 'MyTestStack');
  10 |     
> 11 |     app.synth();
     |         ^
  12 |
  13 |     const template = Template.fromStack(stack);
  14 | });

  at sanitizeId (node_modules/constructs/src/construct.ts:552:13)
  at Node.tryFindChild (node_modules/constructs/src/construct.ts:119:27)
  at createNestedStackParameter (node_modules/aws-cdk-lib/core/lib/private/refs.js:1:6613)
  at resolveValue (node_modules/aws-cdk-lib/core/lib/private/refs.js:1:3177)
  at resolveReferences (node_modules/aws-cdk-lib/core/lib/private/refs.js:1:1516)
  at prepareApp (node_modules/aws-cdk-lib/core/lib/private/prepare-app.js:1:904)
  at synthesize (node_modules/aws-cdk-lib/core/lib/private/synthesis.js:1:1632)
  at App.synth (node_modules/aws-cdk-lib/core/lib/stage.js:1:2365)
  at Object.<anonymous> (test/bug.test.ts:11:9)

Reproduction Steps

export class BugStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    console.log("Creating bug stack");

    let func: IFunction = new Function(this, "AvailabilityZoneMapperFunction", {
        runtime: Runtime.PYTHON_3_12,
        code: Code.fromInline("\ndef handler(event, context):\n  return"),
        handler: "index.handler",
        memorySize: 512,
    });

    let mapper: CustomResource = new CustomResource(this, "AvailabilityZoneMapper", {
      serviceToken: func.functionArn,
    });

    new NestedStackWithReference(this, "NestedStack", {
      mapper: mapper
    });
  }
}

export interface NestedStackWithReferenceProps extends NestedStackProps
{
  readonly mapper: CustomResource;
}

export class NestedStackWithReference extends NestedStack
{
  constructor(scope: Construct, id: string, props: NestedStackWithReferenceProps)
  {
    super(scope, id, props);

    new Queue(this, "Queue", {
      queueName: props.mapper.getAttString(Fn.ref("AWS::Region"))
    }); 
  }
}

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.138.0 (build 6b41c8b)

Framework Version

No response

Node.js Version

v20.9.0

OS

darwin

Language

TypeScript

Language Version

No response

Other information

No response

@hakenmt hakenmt added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels May 9, 2024
@github-actions github-actions bot added the aws-cdk-lib Related to the aws-cdk-lib package label May 9, 2024
@khushail khushail added needs-reproduction This issue needs reproduction. and removed needs-triage This issue or PR still needs to be triaged. labels May 9, 2024
@khushail
Copy link
Contributor

thanks @hakenmt for reaching out and sharing the code. I am able to repro it. However I am investigating the root cause, will share updates soon.

@khushail khushail added investigating This issue is being investigated and/or work is in progress to resolve the issue. p2 effort/medium Medium work item – several days of effort and removed needs-reproduction This issue needs reproduction. labels May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws-cdk-lib Related to the aws-cdk-lib package bug This issue is a bug. effort/medium Medium work item – several days of effort investigating This issue is being investigated and/or work is in progress to resolve the issue. p2
Projects
None yet
Development

No branches or pull requests

2 participants