Skip to content

Commit 4083d04

Browse files
committed
get rid of custom resource
1 parent bff7f50 commit 4083d04

File tree

19 files changed

+37
-508
lines changed

19 files changed

+37
-508
lines changed

.devcontainer/devcontainer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
"python.testing.pytestEnabled": true,
5555
"python.testing.pytestArgs": [
5656
"packages/slackBotFunction",
57-
"packages/createIndexFunction"
5857
],
5958
"python.linting.pylintEnabled": false,
6059
"python.linting.flake8Enabled": true,

.github/workflows/cdk_package_code.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ jobs:
6262
- name: Build Python Lambda Functions
6363
run: |
6464
pip3 install -r packages/slackBotFunction/requirements.txt -t packages/slackBotFunction
65-
pip3 install -r packages/createIndexFunction/requirements.txt -t packages/createIndexFunction
6665
pip3 install -r packages/syncKnowledgeBaseFunction/requirements.txt -t packages/syncKnowledgeBaseFunction
6766
6867
- name: 'Tar files'

.vscode/eps-assist-me.code-workspace

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
"name": "packages/cdk",
99
"path": "../packages/cdk"
1010
},
11-
{
12-
"name": "packages/createIndexFunction",
13-
"path": "../packages/createIndexFunction"
14-
},
1511
{
1612
"name": "packages/slackBotFunction",
1713
"path": "../packages/slackBotFunction"

Makefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ install: install-python install-hooks install-node
1010

1111
install-python:
1212
poetry install
13-
cd packages/createIndexFunction && pip install -r requirements.txt && pip install -r requirements-test.txt
1413
cd packages/slackBotFunction && pip install -r requirements.txt && pip install -r requirements-test.txt
1514
cd packages/syncKnowledgeBaseFunction && pip install -r requirements.txt && pip install -r requirements-test.txt
1615

@@ -46,15 +45,12 @@ lint-flake8:
4645
poetry run flake8 .
4746

4847
test:
49-
cd packages/createIndexFunction && PYTHONPATH=. COVERAGE_FILE=coverage/.coverage python -m pytest
5048
cd packages/slackBotFunction && PYTHONPATH=. COVERAGE_FILE=coverage/.coverage python -m pytest
5149
cd packages/syncKnowledgeBaseFunction && PYTHONPATH=. COVERAGE_FILE=coverage/.coverage python -m pytest
5250

5351
clean:
5452
rm -rf packages/cdk/coverage
5553
rm -rf packages/cdk/lib
56-
rm -rf packages/createIndexFunction/coverage
57-
rm -rf packages/createIndexFunction/.coverage
5854
rm -rf packages/slackBotFunction/coverage
5955
rm -rf packages/slackBotFunction/.coverage
6056
rm -rf packages/syncKnowledgeBaseFunction/coverage

README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ packages/
2828
│ │ └── RestApiGateway/ # API Gateway specific constructs
2929
│ ├── resources/ # AWS resource definitions
3030
│ └── stacks/ # CDK stack definitions
31-
├── createIndexFunction/ # Lambda function for OpenSearch index management
32-
│ ├── app/ # Application code
33-
│ │ ├── config/ # Configuration and environment variables
34-
│ │ └── handler.py # Lambda handler
35-
│ └── tests/ # Unit tests
3631
├── slackBotFunction/ # Lambda function for Slack bot integration
3732
│ ├── app/ # Application code
3833
│ │ ├── config/ # Configuration and environment variables

packages/cdk/nagSuppressions.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,6 @@ export const nagSuppressions = (stack: Stack) => {
1616
]
1717
)
1818

19-
// Suppress wildcard log permissions for CreateIndex Lambda
20-
safeAddNagSuppression(
21-
stack,
22-
"/EpsAssistMeStack/Functions/CreateIndexFunction/LambdaPutLogsManagedPolicy/Resource",
23-
[
24-
{
25-
id: "AwsSolutions-IAM5",
26-
reason: "Wildcard permissions are required for log stream access under known paths."
27-
}
28-
]
29-
)
30-
3119
// Suppress wildcard log permissions for SyncKnowledgeBase Lambda
3220
safeAddNagSuppression(
3321
stack,

packages/cdk/resources/Functions.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,6 @@ export class Functions extends Construct {
4343
constructor(scope: Construct, id: string, props: FunctionsProps) {
4444
super(scope, id)
4545

46-
// Lambda function to create OpenSearch vector index
47-
const createIndexFunction = new LambdaFunction(this, "CreateIndexFunction", {
48-
stackName: props.stackName,
49-
functionName: `${props.stackName}-CreateIndexFunction`,
50-
packageBasePath: "packages/createIndexFunction",
51-
handler: "app.handler.handler",
52-
logRetentionInDays: props.logRetentionInDays,
53-
logLevel: props.logLevel,
54-
environmentVariables: {"INDEX_NAME": props.collectionId},
55-
additionalPolicies: [props.createIndexManagedPolicy]
56-
})
57-
5846
// Lambda function to handle Slack bot interactions (events and @mentions)
5947
const slackBotLambda = new LambdaFunction(this, "SlackBotLambda", {
6048
stackName: props.stackName,
@@ -100,7 +88,6 @@ export class Functions extends Construct {
10088
})
10189

10290
this.functions = {
103-
createIndex: createIndexFunction,
10491
slackBot: slackBotLambda,
10592
syncKnowledgeBase: syncKnowledgeBaseFunction
10693
}
Lines changed: 36 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,56 @@
11
import {Construct} from "constructs"
2-
import {Duration} from "aws-cdk-lib"
3-
import {PolicyStatement} from "aws-cdk-lib/aws-iam"
4-
import {CfnCollection} from "aws-cdk-lib/aws-opensearchserverless"
5-
import {AwsCustomResource, PhysicalResourceId, AwsCustomResourcePolicy} from "aws-cdk-lib/custom-resources"
6-
import {LambdaFunction} from "../constructs/LambdaFunction"
2+
import {CfnCollection, CfnIndex} from "aws-cdk-lib/aws-opensearchserverless"
73

84
export interface VectorIndexProps {
95
readonly indexName: string
106
readonly collection: CfnCollection
11-
readonly createIndexFunction: LambdaFunction
127
readonly endpoint: string
138
}
149

1510
export class VectorIndex extends Construct {
16-
public readonly vectorIndex: AwsCustomResource
11+
public readonly cfnIndex: CfnIndex
1712

1813
constructor(scope: Construct, id: string, props: VectorIndexProps) {
1914
super(scope, id)
2015

21-
// Custom resource to manage OpenSearch vector index lifecycle via Lambda
22-
this.vectorIndex = new AwsCustomResource(this, "VectorIndex", {
23-
installLatestAwsSdk: true,
24-
// Create index when stack is deployed
25-
onCreate: {
26-
service: "Lambda",
27-
action: "invoke",
28-
parameters: {
29-
FunctionName: props.createIndexFunction.function.functionName,
30-
InvocationType: "RequestResponse",
31-
Payload: JSON.stringify({
32-
RequestType: "Create",
33-
CollectionName: props.collection.name,
34-
IndexName: props.indexName,
35-
Endpoint: props.endpoint
36-
})
16+
const indexMapping: CfnIndex.MappingsProperty = {
17+
properties: {
18+
"bedrock-knowledge-base-default-vector": {
19+
type: "knn_vector",
20+
dimension: 1024,
21+
method: {
22+
name: "hnsw",
23+
engine: "faiss",
24+
parameters: {},
25+
spaceType: "l2"
26+
}
3727
},
38-
physicalResourceId: PhysicalResourceId.of(`VectorIndex-${props.indexName}`)
39-
},
40-
// Delete index when stack is destroyed
41-
onDelete: {
42-
service: "Lambda",
43-
action: "invoke",
44-
parameters: {
45-
FunctionName: props.createIndexFunction.function.functionName,
46-
InvocationType: "RequestResponse",
47-
Payload: JSON.stringify({
48-
RequestType: "Delete",
49-
CollectionName: props.collection.name,
50-
IndexName: props.indexName,
51-
Endpoint: props.endpoint
52-
})
28+
"AMAZON_BEDROCK_METADATA": {
29+
type: "text",
30+
index: false
31+
},
32+
"AMAZON_BEDROCK_TEXT_CHUNK": {
33+
type: "text",
34+
index: false
35+
}
36+
}
37+
}
38+
39+
const cfnIndex = new CfnIndex(this, "MyCfnIndex", {
40+
collectionEndpoint: props.endpoint,
41+
indexName: props.indexName,
42+
mappings: indexMapping,
43+
// the properties below are optional
44+
settings: {
45+
index: {
46+
knn: true,
47+
knnAlgoParamEfSearch: 512
5348
}
54-
},
55-
// Grant permission to invoke the Lambda function
56-
policy: AwsCustomResourcePolicy.fromStatements([
57-
new PolicyStatement({
58-
actions: ["lambda:InvokeFunction"],
59-
resources: [props.createIndexFunction.function.functionArn]
60-
})
61-
]),
62-
timeout: Duration.seconds(60)
49+
}
6350
})
6451

6552
// Ensure collection exists before creating index
66-
this.vectorIndex.node.addDependency(props.collection)
53+
cfnIndex.node.addDependency(props.collection)
54+
this.cfnIndex = cfnIndex
6755
}
6856
}

packages/cdk/stacks/EpsAssistMeStack.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,11 @@ export class EpsAssistMeStack extends Stack {
137137
const vectorIndex = new VectorIndex(this, "VectorIndex", {
138138
indexName: VECTOR_INDEX_NAME,
139139
collection: openSearchResources.collection.collection,
140-
createIndexFunction: functions.functions.createIndex,
141140
endpoint
142141
})
143142

144143
// Ensure knowledge base waits for vector index
145-
vectorKB.knowledgeBase.node.addDependency(vectorIndex.vectorIndex)
144+
vectorKB.knowledgeBase.node.addDependency(vectorIndex.cfnIndex)
146145

147146
// Add S3 notification to trigger sync Lambda function
148147
new S3LambdaNotification(this, "S3LambdaNotification", {

packages/createIndexFunction/app/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)