-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathserverless.yml
111 lines (104 loc) · 3.28 KB
/
serverless.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
service: document-chat-demo
provider:
name: aws
runtime: nodejs18.x
architecture: arm64
stage: ${opt:stage, 'prod'}
region: ${opt:region, 'us-east-1'} # Bedrock is only available in select regions; also, other regions may have different models available
memorySize: ${opt:memory, 1024}
logRetentionInDays: 7
versionFunctions: false
deploymentBucket:
blockPublicAccess: true
maxPreviousDeploymentArtifacts: 5
serverSideEncryption: AES256
stackTags:
Usage: ${self:service}
tags:
Usage: ${self:service}
apiGateway:
minimumCompressionSize: 1024
plugins:
- serverless-esbuild
- serverless-offline
- serverless-iam-roles-per-function
package:
individually: true
custom:
awsAccountNumber: 123412341234 # SET THIS VALUE
documentsBucketArn: arn:aws:s3:::${self:custom.documentsBucketName}
documentsBucketName: ${self:service}-some-random-value # SET THIS VALUE
documentsBucketPrefix: documents/
documentsEmbeddingsQueueArn: arn:aws:sqs:${aws:region}:${self:custom.awsAccountNumber}:${self:custom.documentsEmbeddingsQueueName}
documentsEmbeddingsQueueName: ${self:service}-embeddings
openSearchIndex: documents
openSearchUrl: https://random.region.aoss.amazonaws.com # SET THIS VALUE
functions:
Chunk:
handler: src/handlers/chunk.handler
description: Chunk documents
timeout: 30
events:
- s3:
bucket: ${self:custom.documentsBucketName}
event: s3:ObjectCreated:*
rules:
- prefix: ${self:custom.documentsBucketPrefix}
- suffix: .txt
- s3:
bucket: ${self:custom.documentsBucketName}
event: s3:ObjectCreated:*
rules:
- prefix: ${self:custom.documentsBucketPrefix}
- suffix: .pdf
iamRoleStatements:
- Effect: "Allow"
Action:
- sqs:SendMessage
Resource: ${self:custom.documentsEmbeddingsQueueArn}
- Effect: "Allow"
Action:
- s3:GetObject
Resource: "${self:custom.documentsBucketArn}/*"
environment:
AWS_ACCOUNT_NUMBER: ${self:custom.awsAccountNumber}
REGION: ${aws:region}
QUEUE_NAME: ${self:custom.documentsEmbeddingsQueueName}
GenerateEmbeddings:
handler: src/handlers/embed.handler
description: Generate embeddings for uploaded documents
timeout: 30
events:
- sqs:
arn: ${self:custom.documentsEmbeddingsQueueArn}
batchSize: 10
maximumBatchingWindow: 10
functionResponseType: ReportBatchItemFailures
iamRoleStatements:
- Effect: "Allow"
Action:
- aoss:*
- bedrock:InvokeModel
Resource: "*"
environment:
REGION: ${aws:region}
OPENSEARCH_INDEX: ${self:custom.openSearchIndex}
OPENSEARCH_URL: ${self:custom.openSearchUrl}
Ask:
handler: src/handlers/ask.handler
description: Ask the LLM a question
timeout: 29 # Under 30 seconds because of API Gateway max duration
events:
- httpApi:
method: GET
path: /
iamRoleStatements:
- Effect: "Allow"
Action:
- aoss:*
- bedrock:InvokeModel
Resource: "*"
environment:
REGION: ${aws:region}
OPENSEARCH_INDEX: ${self:custom.openSearchIndex}
OPENSEARCH_URL: ${self:custom.openSearchUrl}