Skip to content

Commit f7eaf88

Browse files
committed
Fix template.yml default values for AOSS resources, added requirements.txt to dependencies folder and enabled sam build to build layers, added AOSS Index fields mapping during creation
1 parent f193fab commit f7eaf88

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

s3-lambda-bedrock-aoss/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ Important: this application uses various AWS services and there are costs associ
2525
```
2626
cd s3-lambda-bedrock-aoss
2727
```
28-
3. From the command line, run `build-layer.sh` that would download required dependencies used to create a Lambda Layer
28+
3. Build the layers and prepare the application for deployment
2929
```
30-
./build-layer.sh
30+
sam build
3131
```
3232
4. Use AWS SAM to deploy the AWS resources for the pattern as specified in the template.yml file:
3333
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
crhelper
2+
opensearch-py
3+
PyPDF2

s3-lambda-bedrock-aoss/src/index_creation.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,27 @@ def get_aoss_index_name(resource_properties):
3939

4040
#Function to use the opensearch-py library to create an index within an opensearch collection
4141
def create_aoss_index(index_name, aos_client):
42-
aos_client.indices.create(index=index_name)
42+
43+
index_body = {
44+
"settings": {
45+
"index.knn": True
46+
},
47+
"mappings": {
48+
"properties": {
49+
"page_vector": {
50+
"type": "knn_vector",
51+
"dimension": 1536
52+
},
53+
"page_text": {
54+
"type": "text"
55+
},
56+
"page_number": {
57+
"type" : "integer"
58+
}
59+
}
60+
}
61+
}
62+
aos_client.indices.create(index=index_name, body=index_body)
4363
print(f"Created index {index_name}")
4464

4565
#Handles create event of the CloudFormation resource
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
crhelper
2+
opensearch-py
3+
PyPDF2

s3-lambda-bedrock-aoss/template.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ Parameters:
66
Type: String
77
Description: "The collection name to create for storing vector embeedings"
88
ConstraintDescription: "Must be a valid name for Amazon OpenSearch Service Collection."
9-
Default: "example_collection"
9+
Default: "example-collection"
1010
AmazonOpenSearchIndexName:
1111
Type: String
1212
Description: "The index name to store vector embeedings"
1313
ConstraintDescription: "Must be a valid Amazon OpenSearch Service Vector Index."
14-
Default: "example_index"
14+
Default: "example-index"
1515
BedrockModelRegion:
1616
Type: String
1717
Description: Select the Bedrock service region from available options. Please make sure the model is access granted in the selected region Bedrock service. If your AOS service is in a region that is different than the bedrock service region, you may expect cross-region latency.
@@ -161,6 +161,8 @@ Resources:
161161
ContentUri: dependencies/.
162162
CompatibleRuntimes:
163163
- python3.11
164+
Metadata:
165+
BuildMethod: python3.11
164166

165167
SourceBucket:
166168
Type: AWS::S3::Bucket
@@ -222,4 +224,4 @@ Outputs:
222224
Description: S3 Bucket for object storage
223225
DocumentIngestionLambdaFunctionName:
224226
Value: !Ref DocumentIngestionLambdaFunction
225-
Description: Document Ingestion Lambda Function Name
227+
Description: Document Ingestion Lambda Function Name

0 commit comments

Comments
 (0)