aws-samples / aws-samples/bedrock-chat
[BUG] Error either the bucket name or prefix in the S3 data source is duplicated
- Dominant language
- TypeScript
- Stars
- 1.3k
- Forks
- 535
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 10
Description
## 🚨 **Please Note** 🚨
To ensure efficient investigation of the issue, please fill out the fields below with as much detail as possible. **Reports that do not follow this template may be closed without notification.** We appreciate your cooperation.
## Describe the bug
At knowledge settings, if user inputs duplicated bucket name or prefix in S3 datasource, causes error at `cdk synth`.
If bucket name is duplicated:
- s3://hoge/fuga/
- s3://hoge/piyo/
```
Error: There is already a Construct with name 'hoge' in BedrockCustomBotStack [BrChatKbStack01JG3V7FQZYG5NGX7R87966JTT]
at Node.addChild (/codebuild/output/src1957739235/src/cdk/node_modules/constructs/src/construct.ts:447:13)
at new Node (/codebuild/output/src1957739235/src/cdk/node_modules/constructs/src/construct.ts:71:17)
at new Construct (/codebuild/output/src1957739235/src/cdk/node_modules/constructs/src/construct.ts:499:17)
at new Resource (/codebuild/output/src1957739235/src/cdk/node_modules/aws-cdk-lib/core/lib/resource.js:1:1309)
at new BucketBase (/codebuild/output/src1957739235/src/cdk/node_modules/aws-cdk-lib/aws-s3/lib/bucket.js:1:2172)
at new Import (/codebuild/output/src1957739235/src/cdk/node_modules/aws-cdk-lib/aws-s3/lib/bucket.js:1:16085)
at Function.fromBucketAttributes (/codebuild/output/src1957739235/src/cdk/node_modules/aws-cdk-lib/aws-s3/lib/bucket.js:1:16997)
at Function.fromBucketName (/codebuild/output/src1957739235/src/cdk/node_modules/aws-cdk-lib/aws-s3/lib/bucket.js:1:14937)
at /codebuild/output/src1957739235/src/cdk/lib/bedrock-custom-bot-stack.ts:353:29
at Array.forEach ()
```
If prefix is duplicated:
- s3://hoge/fuga/
- s3://piyo/fuga/
```
Error: There is already a Construct with name 'DataSourcehoge--' in BedrockCustomBotStack [BrChatKbStack01JG3V7FQZYG5NGX7R87966JTT]
at Node.addChild (/codebuild/output/src3955119784/src/cdk/node_modules/constructs/src/construct.ts:447:13)
at new Node (/codebuild/output/src3955119784/src/cdk/node_modules/constructs/src/construct.ts:71:17)
at new Construct (/codebuild/output/src3955119784/src/cdk/node_modules/constructs/src/construct.ts:499:17)
at new Resource (/codebuild/output/src3955119784/src/cdk/node_modules/aws-cdk-lib/core/lib/resource.js:1:1309)
at new DataSourceBase (/codebuild/output/src3955119784/src/cdk/node_modules/@cdklabs/generative-ai-cdk-constructs/src/cdk-lib/bedrock/data-sources/base-data-source.ts:92:1)
at new DataSourceNew (/codebuild/output/src3955119784/src/cdk/node_modules/@cdklabs/generative-ai-cdk-constructs/src/cdk-lib/bedrock/data-sources/base-data-source.ts:162:1)
at new S3DataSource (/codebuild/output/src3955119784/src/cdk/node_modules/@cdklabs/generative-ai-cdk-constructs/src/cdk-lib/bedrock/data-sources/s3-data-source.ts:98:5)
at /codebuild/output/src3955119784/src/cdk/lib/bedrock-custom-bot-stack.ts:119:16
at Array.map ()
at new BedrockCustomBotStack (/codebuild/output/src3955119784/src/cdk/lib/bedrock-custom-bot-stack.ts:116:49)
```
Also, the prefix must end with `/` , but there is no such explanation, and no error message is displayed on UI.
```
"Value error, Invalid S3 URL format (must end with a '/'): s3://hoge/hoge"
```
## To Reproduce
Steps to reproduce the behavior:
1. Go to 'bot console'
2. Click on 'create new bot'
3. Scroll down to 'S3 datasources'
4. Input duplicated:
- duplicated bucket name like `s3://hoge/fuga/` and `s3://hoge/piyo/`
- duplicated prefix like `s3://hoge/fuga/` and `s3://piyo/fuga/`
5. See errors in CodeBuild
## Screenshots

## Additional context
Add any other context about the problem here.
Contributor guide
Research direction
Start in cdk/lib/bedrock-custom-bot-stack.ts at the datasource construction around lines 116-119 and bucket handling around line 353, then reproduce both duplicate-input cases with cdk synth. Trace how the knowledge settings input reaches these entry points. Done means duplicate bucket names and prefixes no longer cause construct errors, and a prefix without a trailing slash produces a visible validation message.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100