generative-ai-cdk-constructs icon indicating copy to clipboard operation
generative-ai-cdk-constructs copied to clipboard

Construct default child properties and L1 customizations

Open leevilehtonen opened this issue 9 months ago • 2 comments

Describe the feature

Not sure if this should be considered as bug or feature. It looks like most of the L2 constructs use arbitrary naming when initializing L1 constructs, e.g.

  • https://github.com/awslabs/generative-ai-cdk-constructs/blob/main/src/cdk-lib/bedrock/agents/agent.ts#L515
  • https://github.com/awslabs/generative-ai-cdk-constructs/blob/main/src/cdk-lib/bedrock/agents/agent-alias.ts#L247
  • https://github.com/awslabs/generative-ai-cdk-constructs/blob/main/src/cdk-lib/kendra/gen-ai-index.ts#L277

The constructs library supports the defaultChild property based on few specific IDs: https://github.com/aws/constructs/blob/10.x/src/construct.ts#L146-L158 which is in a way the basis for doing L1 overrides / customizations mentioned in AWS CDK documentation https://docs.aws.amazon.com/cdk/v2/guide/cfn_layer.html

The request would be to change the L1 construct initializing to use logical IDs which link to defaultChild -property automatically.

As a reference, compared to aws-cdk-lib the usage of L1 logical IDs is consistent to support the defaultChild https://github.com/aws/aws-cdk/blob/v2.184.1/packages/aws-cdk-lib/aws-sqs/lib/queue.ts#L416 https://github.com/aws/aws-cdk/blob/v2.184.1/packages/aws-cdk-lib/aws-codepipeline/lib/pipeline.ts#L549

(This is of course bit problematic since changing the logical IDs would recreate the resources in CFN, which maybe particularly annoying if using hardcoded names. So in a way this should be probably treated as a breaking change.)

Use Case

Doing CFN level customizations and overrides https://docs.aws.amazon.com/cdk/v2/guide/cfn_layer.html without the need for "searching" the correct child construct.

Proposed Solution

No response

Other Information

No response

Acknowledgements

  • [ ] I may be able to implement this feature request
  • [x] This feature might incur a breaking change

leevilehtonen avatar Mar 18 '25 19:03 leevilehtonen

Hi @leevilehtonen, thanks for the great suggestion! As you pointed out, these changes could potentially break deployments for users upgrading to the new version. Even though the library is still experimental and has disclaimers about its stability, we need to establish a plan to minimize the impact.

aws-rafams avatar Mar 27 '25 17:03 aws-rafams

struggled with this too, while trying to configure MultiModal DataSource.

To make the workaround a little more obvious:

use node.findChild with the ID you retrieve from the source code of the construct. For example in the case of a datasource:

const cfnDataSource = dataSource.node.findChild('DataSource') as bedrock.CfnDataSource;

jwoehrle avatar Apr 29 '25 15:04 jwoehrle

This issue is now marked as stale because it hasn't seen activity for a while. Add a comment or it will be closed soon. If you wish to exclude this issue from being marked as stale, add the "backlog" label.

github-actions[bot] avatar Jun 29 '25 01:06 github-actions[bot]

Closing this issue as it hasn't seen activity for a while. Please add a comment @mentioning a maintainer to reopen. If you wish to exclude this issue from being marked as stale, add the "backlog" label.

github-actions[bot] avatar Jul 07 '25 01:07 github-actions[bot]