Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

CDK NestedStack: Accessing a nested stack resource in a stack resolves to Amazon.JSII.Runtime.Deputy.AnonymousObject and cannot be casted to CfnStack #30497

Open
hakenmt opened this issue Jun 9, 2024 · 2 comments
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug. jsii This issue originates in jsii, or this feature must be implemented in jsii. p3

Comments

@hakenmt
Copy link

hakenmt commented Jun 9, 2024

Describe the bug

I have use case that I need to add parameters being provided to a nested stack that is created by an AWS provided EKS construct (in this case the nested stacks containing the Kubectl and resource provider lambda functions). I can find the resources in the node tree, but they cannot be casted to a CfnStack, they are of type Amazon.JSII.Runtime.Deputy.AnonymousObject and I cannot access the parameters property of the stack. This results in having to manipulate the rendered CloudFormation template to achieve the desired outcome.

Expected Behavior

Be able to access a nested stack resource and cast it to a CfnStack.

Current Behavior

The only available type is Amazon.JSII.Runtime.Deputy.AnonymousObject.

Reproduction Steps

FixUpResourceProvider("@aws-cdk--aws-eks.ClusterResourceProvider");
FixUpResourceProvider("@aws-cdk--aws-eks.KubectlProvider");

private void FixUpResourceProvider(string name)
{
            IConstruct resourceProviderNestedStack = this.Node.TryFindChild(name);

            // Add the parameters to the actual nested stack so it can receive them
            if (resourceProviderNestedStack != null)
            {
                NestedStack nestedStack = resourceProviderNestedStack as NestedStack;

                var nestedStackResource = nestedStack.NestedStackResource as CfnStack;

                nestedStackResource.Parameters.GetType() == typeof(Amazon.JSII.Runtime.Deputy.AnonymousObject)
            }
}

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.138.0

Framework Version

No response

Node.js Version

v20.9.0

OS

darwin

Language

.NET

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 Jun 9, 2024
@github-actions github-actions bot added the @aws-cdk/core Related to core CDK functionality label Jun 9, 2024
@pahud
Copy link
Contributor

pahud commented Jun 13, 2024

Sounds related to JSII but I am wondering what you are trying to do with aws-eks construct?

@pahud pahud added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. p3 jsii This issue originates in jsii, or this feature must be implemented in jsii. and removed needs-triage This issue or PR still needs to be triaged. labels Jun 13, 2024
@hakenmt
Copy link
Author

hakenmt commented Jun 13, 2024

The automatically created Lambda functions get created in nested stacks. For my use case, I can't use the automatically defined CDK bucket, the bucket name is provided as a parameter to the main stack at runtime. So I do this in my synthesizer:

Synthesizer = new DefaultStackSynthesizer(new DefaultStackSynthesizerProps() {
                    FileAssetsBucketName = "${AssetsBucket}",
                    BucketPrefix = "${AssetsBucketPrefix}",
                    Qualifier = null,
                    GenerateBootstrapVersionRule = false              
                })

Then, the asset s3 code path is set to use this variable when synth is run. In stacks/nested stacks I control, I can pass the received value of the parent stack parameter to those nested stacks (add CfnParameter objects to the nested stack and also specify parameters in the nested stack resource props). For the nested stacks created by the EKS construct I cannot. Trying to manipulate the nested stack resource through node tree isn't successful since I can't actually cast the nested stack resource to something that I can manipulate to add the parameters property.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jun 13, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug. jsii This issue originates in jsii, or this feature must be implemented in jsii. p3
Projects
None yet
Development

No branches or pull requests

2 participants