Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/cdk/resources/BedrockExecutionRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ManagedPolicy
} from "aws-cdk-lib/aws-iam"
import {Bucket} from "aws-cdk-lib/aws-s3"
import {Key} from "aws-cdk-lib/aws-kms"

// Amazon Titan embedding model for vector generation
const EMBEDDING_MODEL = "amazon.titan-embed-text-v2:0"
Expand All @@ -14,6 +15,7 @@ export interface BedrockExecutionRoleProps {
readonly region: string
readonly account: string
readonly kbDocsBucket: Bucket
readonly kbDocsKmsKey: Key
}

export class BedrockExecutionRole extends Construct {
Expand Down Expand Up @@ -63,7 +65,7 @@ export class BedrockExecutionRole extends Construct {
// KMS permissions for S3 bucket encryption
const kmsAccessPolicy = new PolicyStatement({
actions: ["kms:Decrypt", "kms:DescribeKey"],
resources: ["*"],
resources: [props.kbDocsKmsKey.keyArn],
conditions: {"StringEquals": {"aws:ResourceAccount": props.account}}
})

Expand Down
10 changes: 8 additions & 2 deletions packages/cdk/resources/Storage.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import {Construct} from "constructs"
import {S3Bucket} from "../constructs/S3Bucket"
import {Key} from "aws-cdk-lib/aws-kms"
import {Bucket} from "aws-cdk-lib/aws-s3"

export interface StorageProps {
readonly stackName: string
}

export class Storage extends Construct {
public readonly kbDocsBucket: S3Bucket
public readonly kbDocsBucket: Bucket
public readonly kbDocsKmsKey: Key

constructor(scope: Construct, id: string, props: StorageProps) {
super(scope, id)

// Create S3 bucket for knowledge base documents with encryption
this.kbDocsBucket = new S3Bucket(this, "DocsBucket", {
const kbDocsBucket = new S3Bucket(this, "DocsBucket", {
bucketName: `${props.stackName}-Docs`,
versioned: true
})

this.kbDocsBucket = kbDocsBucket.bucket
this.kbDocsKmsKey = kbDocsBucket.kmsKey
}
}
11 changes: 6 additions & 5 deletions packages/cdk/stacks/EpsAssistMeStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ export class EpsAssistMeStack extends Stack {
const bedrockExecutionRole = new BedrockExecutionRole(this, "BedrockExecutionRole", {
region,
account,
kbDocsBucket: storage.kbDocsBucket.bucket
kbDocsBucket: storage.kbDocsBucket,
kbDocsKmsKey: storage.kbDocsKmsKey
})

// Create OpenSearch Resources with Bedrock execution role
Expand All @@ -108,7 +109,7 @@ export class EpsAssistMeStack extends Stack {
// Create VectorKnowledgeBase construct with Bedrock execution role
const vectorKB = new VectorKnowledgeBaseResources(this, "VectorKB", {
stackName: props.stackName,
docsBucket: storage.kbDocsBucket.bucket,
docsBucket: storage.kbDocsBucket,
bedrockExecutionRole: bedrockExecutionRole.role,
collectionArn: openSearchResources.collection.collectionArn,
vectorIndexName: vectorIndex.indexName,
Expand Down Expand Up @@ -167,7 +168,7 @@ export class EpsAssistMeStack extends Stack {

// Add S3 notification to trigger sync Lambda function
new S3LambdaNotification(this, "S3LambdaNotification", {
bucket: storage.kbDocsBucket.bucket,
bucket: storage.kbDocsBucket,
lambdaFunction: functions.syncKnowledgeBaseFunction.function
})

Expand Down Expand Up @@ -229,11 +230,11 @@ export class EpsAssistMeStack extends Stack {
})

new CfnOutput(this, "kbDocsBucketArn", {
value: storage.kbDocsBucket.bucket.bucketArn,
value: storage.kbDocsBucket.bucketArn,
exportName: `${props.stackName}:kbDocsBucket:Arn`
})
new CfnOutput(this, "kbDocsBucketName", {
value: storage.kbDocsBucket.bucket.bucketName,
value: storage.kbDocsBucket.bucketName,
exportName: `${props.stackName}:kbDocsBucket:Name`
})

Expand Down