Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
fd57c6e
chore: force rebuild
kieran-wilkinson-4 Feb 26, 2026
1b49ea8
feat: Use Slack Plan
kieran-wilkinson-4 Feb 27, 2026
4d0adba
feat: Use Slack Plan - skip tests
kieran-wilkinson-4 Feb 27, 2026
eb5a7f8
feat: Use Slack Plan - skip tests
kieran-wilkinson-4 Feb 27, 2026
a49be94
chore: force rebuild
kieran-wilkinson-4 Feb 27, 2026
dec8574
chore: force rebuild
kieran-wilkinson-4 Feb 27, 2026
bbd38d8
fix: unit test
kieran-wilkinson-4 Mar 2, 2026
de5cb19
fix: unit test - lock update
kieran-wilkinson-4 Mar 2, 2026
99c171f
fix: unit test - update cdk
kieran-wilkinson-4 Mar 2, 2026
58647b1
fix: unit test - update cdk
kieran-wilkinson-4 Mar 2, 2026
84644f2
fix: unit test - update env variables
kieran-wilkinson-4 Mar 2, 2026
1b3d60b
fix: unit test - policies
kieran-wilkinson-4 Mar 2, 2026
b5217c4
fix: more logs
kieran-wilkinson-4 Mar 2, 2026
f510150
fix: missing properties
kieran-wilkinson-4 Mar 2, 2026
b1bc03a
fix: force rebuild #skip-qc
kieran-wilkinson-4 Mar 2, 2026
e9e1767
fix: force rebuild #skip-qc
kieran-wilkinson-4 Mar 2, 2026
e6e1ba5
fix: force rebuild #skip-qc
kieran-wilkinson-4 Mar 2, 2026
5b68162
fix: handle errors #skip-qc
kieran-wilkinson-4 Mar 2, 2026
a3896e9
fix: handle errors #skip-qc
kieran-wilkinson-4 Mar 2, 2026
0d35aed
fix: use correct enums #skip-qc
kieran-wilkinson-4 Mar 2, 2026
b92a18b
fix: use correct enums #skip-qc
kieran-wilkinson-4 Mar 2, 2026
95cbd0e
fix: merge events
kieran-wilkinson-4 Mar 3, 2026
6dc8b7e
fix: add basic tests for slack
kieran-wilkinson-4 Mar 3, 2026
c5cfccf
fix: add basic tests for slack
kieran-wilkinson-4 Mar 3, 2026
3aaa58a
fix: expect a single message instead of multiple
kieran-wilkinson-4 Mar 3, 2026
c0dad2a
fix: expect a single message instead of multiple
kieran-wilkinson-4 Mar 3, 2026
49b543b
fix: expect a single message instead of multiple
kieran-wilkinson-4 Mar 4, 2026
261c698
fix: expect a single message instead of multiple
kieran-wilkinson-4 Mar 4, 2026
959db5d
fix: expect a single message instead of multiple
kieran-wilkinson-4 Mar 4, 2026
35008f1
fix: Add quiet logging #skip-qc
kieran-wilkinson-4 Mar 4, 2026
0b58a59
fix: rebatch requests #skip-qc
kieran-wilkinson-4 Mar 4, 2026
11ffc56
fix: rebatch requests #skip-qc
kieran-wilkinson-4 Mar 4, 2026
f8ad99a
fix: test batching
kieran-wilkinson-4 Mar 5, 2026
575b50c
fix: test batching #skip-qc
kieran-wilkinson-4 Mar 5, 2026
1b0642b
fix: Multiple message handling #skip-qc
kieran-wilkinson-4 Mar 5, 2026
b0919e3
fix: Multiple message handling #skip-qc
kieran-wilkinson-4 Mar 5, 2026
fae3655
fix: Force rebuild
kieran-wilkinson-4 Mar 5, 2026
ee3c7d9
Merge branch 'main' into AEA-6316-Fix-Slack-Notification
kieran-wilkinson-4 Mar 5, 2026
17fba24
fix: Test Document processing without slack
kieran-wilkinson-4 Mar 6, 2026
18e9f75
fix: Test Document processing with slack
kieran-wilkinson-4 Mar 6, 2026
7ba2b34
fix: Add extra logging #skip-qc
kieran-wilkinson-4 Mar 6, 2026
31341c2
fix: Fix slack function error
kieran-wilkinson-4 Mar 6, 2026
5682b21
fix: Fix cdk permissions
kieran-wilkinson-4 Mar 6, 2026
ebc6086
fix: errors block completion
kieran-wilkinson-4 Mar 6, 2026
b8a6c93
fix: Fetch all events from SQS
kieran-wilkinson-4 Mar 9, 2026
fe0eb85
fix: Poll SQS on first message
kieran-wilkinson-4 Mar 9, 2026
96187fd
fix: Poll SQS on first message
kieran-wilkinson-4 Mar 9, 2026
d7908e5
fix: Poll SQS on first message
kieran-wilkinson-4 Mar 9, 2026
a2dd113
fix: Update unit tests
kieran-wilkinson-4 Mar 10, 2026
6533557
fix: Add silent mode for Slack
kieran-wilkinson-4 Mar 10, 2026
3aed71b
fix: Add silent mode for Slack
kieran-wilkinson-4 Mar 10, 2026
95e3f76
fix: Add silent mode for Slack
kieran-wilkinson-4 Mar 10, 2026
634b1c5
fix: Add silent mode for Slack
kieran-wilkinson-4 Mar 10, 2026
c7c0208
fix: Add silent mode for Slack
kieran-wilkinson-4 Mar 10, 2026
1d54f19
fix: Add silent mode for Slack
kieran-wilkinson-4 Mar 10, 2026
8919bd7
fix: Add silent mode for Slack
kieran-wilkinson-4 Mar 10, 2026
26a241d
fix: Add silent mode for Slack
kieran-wilkinson-4 Mar 10, 2026
0d9c3b5
fix: search for historic conversations
kieran-wilkinson-4 Mar 13, 2026
fec1e94
Merge branch 'main' into AEA-6316-Fix-Slack-Notification
kieran-wilkinson-4 Mar 13, 2026
5956eff
fix: Trivy update Black
kieran-wilkinson-4 Mar 13, 2026
960e64a
fix: handle multiple file changes
kieran-wilkinson-4 Mar 13, 2026
d52249f
fix: handle multiple messages
kieran-wilkinson-4 Mar 13, 2026
ebbd7a5
fix: handle multiple messages
kieran-wilkinson-4 Mar 13, 2026
afc9721
fix: handle multiple slack messages
kieran-wilkinson-4 Mar 13, 2026
b85b488
fix: Use DynamoDb for slack history
kieran-wilkinson-4 Mar 16, 2026
f2d87d4
fix: Use DynamoDb for updated file history
kieran-wilkinson-4 Mar 16, 2026
365ee42
Chore: [AEA-0000] - fix sync role permissions so it does not clash wi…
anthony-nhs Mar 16, 2026
0798cce
Upgrade: [dependabot] - bump pyjwt from 2.11.0 to 2.12.0 (#466)
dependabot[bot] Mar 16, 2026
b08e4fb
Upgrade: [dependabot] - bump slack-sdk from 3.40.1 to 3.41.0 (#459)
dependabot[bot] Mar 16, 2026
71f1d5f
Upgrade: [dependabot] - bump moto from 5.1.21 to 5.1.22 (#465)
dependabot[bot] Mar 16, 2026
00b64f4
Upgrade: [dependabot] - bump cfn-lint from 1.44.0 to 1.46.0 (#444)
dependabot[bot] Mar 16, 2026
ce49441
fix: Merge Main fix poetry lock
kieran-wilkinson-4 Mar 16, 2026
f6010c7
Merge branch 'main' into AEA-6316-Fix-Slack-Notification
kieran-wilkinson-4 Mar 16, 2026
9d3db6b
fix: Merge poetry lock changes
kieran-wilkinson-4 Mar 16, 2026
860a8ce
Merge branch 'main' into AEA-6316-Fix-Slack-Notification
Mar 16, 2026
25cb420
fix: update poetry - again
Mar 16, 2026
cce3da6
fix: Roll back merge conflict
Mar 16, 2026
5e3aa5e
Merge branch 'main' into AEA-6316-Fix-Slack-Notification
Mar 16, 2026
3493e9d
fix: fix poetry issue
Mar 16, 2026
3c22538
fix: Empty Object errors
Mar 16, 2026
abeafc6
Merge branch 'main' into AEA-6316-Fix-Slack-Notification
Mar 16, 2026
81adb55
fix: poetry conflict
Mar 16, 2026
0100213
fix: missing key for dynamo
Mar 16, 2026
03aea06
fix: missing key for dynamo
Mar 16, 2026
2256926
fix: Increase lambda timeout to account for higher file counts
Mar 16, 2026
25be30f
fix: Do not close received events
Mar 17, 2026
360ef34
fix: Do not close initial event
Mar 17, 2026
437677a
Merge branch 'main' into AEA-6316-Fix-Slack-Notification
Mar 17, 2026
62ea295
fix: resolve comments
Mar 20, 2026
6501843
fix: resolve comments
Mar 20, 2026
c75a011
Merge branch 'main' into AEA-6316-Fix-Slack-Notification
bencegadanyi1-nhs Mar 20, 2026
7f87099
fix: use query for dynamo
Mar 20, 2026
d132d8c
Merge branch 'main' into AEA-6316-Fix-Slack-Notification
bencegadanyi1-nhs Mar 23, 2026
1497d2b
Merge branch 'main' into AEA-6316-Fix-Slack-Notification
bencegadanyi1-nhs Mar 26, 2026
88b961f
Merge branch 'main' into AEA-6316-Fix-Slack-Notification
bencegadanyi1-nhs Mar 27, 2026
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
7 changes: 0 additions & 7 deletions .github/workflows/cdk_package_code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ jobs:
run: |
poetry show --only=slackBotFunction | grep -E "^[a-zA-Z]" | awk '{print $1"=="$2}' > requirements_slackBotFunction
poetry show --only=syncKnowledgeBaseFunction | grep -E "^[a-zA-Z]" | awk '{print $1"=="$2}' > requirements_syncKnowledgeBaseFunction
poetry show --only=notifyS3UploadFunction | grep -E "^[a-zA-Z]" | awk '{print $1"=="$2}' > requirements_notifyS3UploadFunction
poetry show --only=preprocessingFunction | grep -E "^[a-zA-Z]" | awk '{print $1"=="$2}' > requirements_preprocessingFunction
poetry show --only=bedrockLoggingConfigFunction | grep -E "^[a-zA-Z]" | awk '{print $1"=="$2}' > requirements_bedrockLoggingConfigFunction
if [ ! -s requirements_slackBotFunction ] || [ "$(grep -c -v '^[[:space:]]*$' requirements_slackBotFunction)" -eq 0 ]; then \
Expand All @@ -65,10 +64,6 @@ jobs:
echo "Error: requirements_syncKnowledgeBaseFunction is empty or contains only blank lines"; \
exit 1; \
fi
if [ ! -s requirements_notifyS3UploadFunction ] || [ "$(grep -c -v '^[[:space:]]*$' requirements_notifyS3UploadFunction)" -eq 0 ]; then \
echo "Error: requirements_notifyS3UploadFunction is empty or contains only blank lines"; \
exit 1; \
fi
if [ ! -s requirements_preprocessingFunction ] || [ "$(grep -c -v '^[[:space:]]*$' requirements_preprocessingFunction)" -eq 0 ]; then \
echo "Error: requirements_preprocessingFunction is empty or contains only blank lines"; \
exit 1; \
Expand All @@ -79,13 +74,11 @@ jobs:
fi
mkdir -p .dependencies/slackBotFunction/python
mkdir -p .dependencies/syncKnowledgeBaseFunction/python
mkdir -p .dependencies/notifyS3UploadFunction/python
mkdir -p .dependencies/preprocessingFunction/python
mkdir -p .dependencies/bedrockLoggingConfigFunction/python
pip3 install -r requirements_slackBotFunction -t .dependencies/slackBotFunction/python
pip3 install -r requirements_syncKnowledgeBaseFunction -t .dependencies/syncKnowledgeBaseFunction/python
pip3 install -r requirements_preprocessingFunction -t .dependencies/preprocessingFunction/python
pip3 install -r requirements_notifyS3UploadFunction -t .dependencies/notifyS3UploadFunction/python
pip3 install -r requirements_bedrockLoggingConfigFunction -t .dependencies/bedrockLoggingConfigFunction/python
rm -rf .dependencies/preprocessingFunction/python/magika* .dependencies/preprocessingFunction/python/onnxruntime*
cp packages/preprocessingFunction/magika_shim.py .dependencies/preprocessingFunction/python/magika.py
Expand Down
4 changes: 0 additions & 4 deletions .vscode/eps-assist-me.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
"name": "packages/syncKnowledgeBaseFunction",
"path": "../packages/syncKnowledgeBaseFunction"
},
{
"name": "packages/notifyS3UploadFunction",
"path": "../packages/notifyS3UploadFunction"
},
{
"name": "packages/preprocessingFunction",
"path": "../packages/preprocessingFunction"
Expand Down
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ lint-flake8:
test:
cd packages/slackBotFunction && PYTHONPATH=. COVERAGE_FILE=coverage/.coverage poetry run python -m pytest
cd packages/syncKnowledgeBaseFunction && PYTHONPATH=. COVERAGE_FILE=coverage/.coverage poetry run python -m pytest
cd packages/notifyS3UploadFunction && PYTHONPATH=. COVERAGE_FILE=coverage/.coverage poetry run python -m pytest
cd packages/preprocessingFunction && PYTHONPATH=. COVERAGE_FILE=coverage/.coverage poetry run python -m pytest
cd packages/bedrockLoggingConfigFunction && PYTHONPATH=. COVERAGE_FILE=coverage/.coverage poetry run python -m pytest

Expand Down Expand Up @@ -83,7 +82,6 @@ cdk-synth: cdk-synth-pr cdk-synth-non-pr
cdk-synth-non-pr:
mkdir -p .dependencies/slackBotFunction
mkdir -p .dependencies/syncKnowledgeBaseFunction
mkdir -p .dependencies/notifyS3UploadFunction
mkdir -p .dependencies/preprocessingFunction
mkdir -p .dependencies/bedrockLoggingConfigFunction
mkdir -p .local_config
Expand All @@ -104,7 +102,6 @@ cdk-synth-non-pr:
cdk-synth-pr:
mkdir -p .dependencies/slackBotFunction
mkdir -p .dependencies/syncKnowledgeBaseFunction
mkdir -p .dependencies/notifyS3UploadFunction
mkdir -p .dependencies/preprocessingFunction
mkdir -p .dependencies/bedrockLoggingConfigFunction
mkdir -p .local_config
Expand Down
Empty file.
Empty file.
7 changes: 5 additions & 2 deletions packages/cdk/constructs/LambdaFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export interface LambdaFunctionProps {
readonly logRetentionInDays: number
readonly logLevel: string
readonly dependencyLocation?: string
readonly reservedConcurrentExecutions?: number
readonly timeout_in_seconds?: Duration
}

// Lambda Insights layer for enhanced monitoring
Expand Down Expand Up @@ -131,7 +133,7 @@ export class LambdaFunction extends Construct {
const lambdaFunction = new LambdaFunctionResource(this, props.functionName, {
runtime: Runtime.PYTHON_3_14,
memorySize: 256,
timeout: Duration.seconds(50),
timeout: props.timeout_in_seconds ?? Duration.seconds(50),
architecture: Architecture.X86_64,
handler: props.handler,
code: Code.fromAsset(props.packageBasePath, {
Expand All @@ -149,7 +151,8 @@ export class LambdaFunction extends Construct {
POWERTOOLS_LOG_LEVEL: props.logLevel
},
logGroup,
layers: layers
layers: layers,
reservedConcurrentExecutions: props.reservedConcurrentExecutions
})

// Suppress CFN guard rules for Lambda function
Expand Down
24 changes: 12 additions & 12 deletions packages/cdk/constructs/SimpleQueueService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ import {LambdaFunction} from "./LambdaFunction"
export interface SimpleQueueServiceProps {
readonly stackName: string
readonly queueName: string
readonly batchDelay: number
readonly functions: Array<LambdaFunction>
}

/**
* AWS Simple Queue Service
* @see {@link https://aws.amazon.com/sqs/}
*/
export class SimpleQueueService extends Construct {
public queue: Queue
public deadLetterQueue: Queue
Expand All @@ -31,10 +34,9 @@ export class SimpleQueueService extends Construct {
// Create a Dead-Letter Queue (DLQ) for handling failed messages, to help with debugging
const deadLetterQueue = new Queue(this, `${name}-dlq`, {
queueName: `${name}-dlq`,
retentionPeriod: Duration.days(14), // Max 14
retentionPeriod: Duration.days(14), // Max
encryption: QueueEncryption.KMS,
encryptionMasterKey: kmsKey,
visibilityTimeout: Duration.seconds(60),
enforceSSL: true
})

Expand All @@ -46,30 +48,28 @@ export class SimpleQueueService extends Construct {
encryptionMasterKey: kmsKey,
deadLetterQueue: {
queue: deadLetterQueue,
maxReceiveCount: 3 // Move to DLQ after 3 failed attempts
maxReceiveCount: 1 // Move to DLQ after a failed attempt
},
deliveryDelay: Duration.seconds(0),
visibilityTimeout: Duration.seconds(60),
deliveryDelay: Duration.seconds(10),
visibilityTimeout: Duration.hours(1), // Really high visibility to prevent multiple calls
enforceSSL: true
}
)

// Add queues as event source for the notify function and sync knowledge base function
// While batching, the messages will be sent if maxBatchingWindow is reached or batchSize is reached
// Set (very) large batch size to improve wait efficiency of batching window
const eventSource = new SqsEventSource(queue, {
maxBatchingWindow: Duration.seconds(props.batchDelay),
batchSize: 1000,
reportBatchItemFailures: true
maxBatchingWindow: Duration.seconds(30),
batchSize: 20
})

props.functions.forEach(fn => {
fn.function.addEventSource(eventSource)
fn.function.addEnvironment("SQS_URL", queue.queueUrl)

queue.grantConsumeMessages(fn.function)
})

// Grant the Lambda function permissions to consume messages from the queue

this.kmsKey = kmsKey
this.queue = queue
this.deadLetterQueue = deadLetterQueue
Expand Down
25 changes: 13 additions & 12 deletions packages/cdk/nagSuppressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@ export const nagSuppressions = (stack: Stack, account: string) => {
]
)

// Suppress wildcard log permissions for NotifyS3UploadFunction Lambda
safeAddNagSuppression(
stack,
"/EpsAssistMeStack/Functions/NotifyS3UploadFunction/LambdaPutLogsManagedPolicy/Resource",
[
{
id: "AwsSolutions-IAM5",
reason: "Wildcard permissions are required for log stream access under known paths."
}
]
)

// Suppress wildcard log permissions for Preprocessing Lambda
safeAddNagSuppression(
stack,
Expand Down Expand Up @@ -174,6 +162,18 @@ export const nagSuppressions = (stack: Stack, account: string) => {
]
)

// Suppress wildcard permissions for Preprocessing policy
safeAddNagSuppression(
stack,
"/EpsAssistMeStack/RuntimePolicies/SyncKnowledgeBasePolicy/Resource",
[
{
id: "AwsSolutions-IAM5",
reason: "Preprocessing Lambda needs wildcard permissions to read/write any file in raw/ and processed/ prefixes."
}
]
)

// Suppress secrets without rotation
safeAddNagSuppressionGroup(
stack,
Expand Down Expand Up @@ -460,6 +460,7 @@ export const nagSuppressions = (stack: Stack, account: string) => {
}
]
)

// Suppress BedrockLogging Provider framework runtime version
safeAddNagSuppression(
stack,
Expand Down
14 changes: 14 additions & 0 deletions packages/cdk/resources/DatabaseTables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface TablesProps {

export class DatabaseTables extends Construct {
public readonly slackBotStateTable: DynamoDbTable
public readonly knowledgeSyncStateTable: DynamoDbTable

constructor(scope: Construct, id: string, props: TablesProps) {
super(scope, id)
Expand All @@ -24,5 +25,18 @@ export class DatabaseTables extends Construct {
},
timeToLiveAttribute: "ttl"
})

this.knowledgeSyncStateTable = new DynamoDbTable(this, "KnowledgeSyncStateTable", {
tableName: `${props.stackName}-KnowledgeSyncState`,
partitionKey: {
name: "user_channel_composite",
type: AttributeType.STRING
},
sortKey: {
name: "last_ts",
type: AttributeType.STRING
},
timeToLiveAttribute: "ttl"
})
}
}
25 changes: 6 additions & 19 deletions packages/cdk/resources/Functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ export interface FunctionsProps {
readonly mainSlackBotLambdaExecutionRoleArn : string
readonly ragModelId: string
readonly reformulationModelId: string
readonly notifyS3UploadFunctionPolicy: ManagedPolicy
readonly docsBucketName: string
readonly knowledgeSyncStateTable: TableV2
}

export class Functions extends Construct {
public readonly slackBotLambda: LambdaFunction
public readonly syncKnowledgeBaseFunction: LambdaFunction
public readonly notifyS3UploadFunction: LambdaFunction
public readonly preprocessingFunction: LambdaFunction

constructor(scope: Construct, id: string, props: FunctionsProps) {
Expand Down Expand Up @@ -130,29 +129,17 @@ export class Functions extends Construct {
dependencyLocation: ".dependencies/syncKnowledgeBaseFunction",
environmentVariables: {
"KNOWLEDGEBASE_ID": props.knowledgeBaseId,
"DATA_SOURCE_ID": props.dataSourceId
},
additionalPolicies: [props.syncKnowledgeBaseManagedPolicy]
})

const notifyS3UploadFunction = new LambdaFunction(this, "NotifyS3UploadFunction", {
stackName: props.stackName,
functionName: `${props.stackName}-S3UpdateFunction`,
packageBasePath: "packages/notifyS3UploadFunction",
handler: "app.handler.handler",
logRetentionInDays: props.logRetentionInDays,
logLevel: props.logLevel,
dependencyLocation: ".dependencies/notifyS3UploadFunction",
environmentVariables: {
"SLACK_BOT_TOKEN_PARAMETER": props.slackBotTokenParameter.parameterName,
"SLACK_BOT_ACTIVE_ON_PRS": "false"
"SLACK_BOT_ACTIVE": `${!props.isPullRequest}`,
"DATA_SOURCE_ID": props.dataSourceId,
"KNOWLEDGE_SYNC_STATE_TABLE": props.knowledgeSyncStateTable.tableName
},
additionalPolicies: [props.notifyS3UploadFunctionPolicy]
additionalPolicies: [props.syncKnowledgeBaseManagedPolicy],
reservedConcurrentExecutions: 1
})

this.slackBotLambda = slackBotLambda
this.preprocessingFunction = preprocessingFunction
this.syncKnowledgeBaseFunction = syncKnowledgeBaseFunction
this.notifyS3UploadFunction = notifyS3UploadFunction
}
}
58 changes: 39 additions & 19 deletions packages/cdk/resources/RuntimePolicies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export interface RuntimePoliciesProps {
readonly slackSigningSecretParameterName: string
readonly slackBotStateTableArn: string
readonly slackBotStateTableKmsKeyArn: string
readonly knowledgeSyncStateTableArn: string
readonly knowledgeSyncStateTableKmsKeyArn: string
readonly knowledgeBaseArn: string
readonly guardrailArn: string
readonly dataSourceArn: string
Expand All @@ -21,7 +23,6 @@ export interface RuntimePoliciesProps {
export class RuntimePolicies extends Construct {
public readonly slackBotPolicy: ManagedPolicy
public readonly syncKnowledgeBasePolicy: ManagedPolicy
public readonly notifyS3UploadFunctionPolicy: ManagedPolicy
public readonly preprocessingPolicy: ManagedPolicy

constructor(scope: Construct, id: string, props: RuntimePoliciesProps) {
Expand Down Expand Up @@ -123,40 +124,59 @@ export class RuntimePolicies extends Construct {
]
})

// Create managed policy for SyncKnowledgeBase Lambda function
const syncKnowledgeBasePolicy = new PolicyStatement({
const syncKnowledgeBaseBedrockPolicy = new PolicyStatement({
actions: [
"bedrock:StartIngestionJob",
"bedrock:GetIngestionJob",
"bedrock:ListIngestionJobs"
],
resources: [
props.knowledgeBaseArn,
props.dataSourceArn
props.knowledgeBaseArn
]
})

this.syncKnowledgeBasePolicy = new ManagedPolicy(this, "SyncKnowledgeBasePolicy", {
description: "Policy for SyncKnowledgeBase Lambda to trigger ingestion jobs",
statements: [syncKnowledgeBasePolicy]
})

// Create managed policy for S3UpdateNotification Lambda function
const notifyS3UploadFunctionPolicy = new PolicyStatement({
const syncKnowledgeBaseSSMPolicy = new PolicyStatement({
actions: [
"ssm:GetParameter",
"sqs:ReceiveMessage",
"sqs:DeleteMessage"
"ssm:GetParameter"
],
resources: [
props.knowledgeBaseArn,
...slackBotPolicyResources
]
})

this.notifyS3UploadFunctionPolicy = new ManagedPolicy(this, "notifyS3UploadFunctionPolicy", {
description: "Policy for S3UpdateNotification Lambda to access SSM parameters",
statements: [notifyS3UploadFunctionPolicy]
const knowledgeSyncDynamoDbPolicy = new PolicyStatement({
actions: [
"dynamodb:GetItem",
"dynamodb:PutItem",
"dynamodb:DeleteItem",
"dynamodb:Query",
"dynamodb:Scan",
"dynamodb:BatchGetItem",
"dynamodb:BatchWriteItem",
"dynamodb:UpdateItem"
],
resources: [props.knowledgeSyncStateTableArn]
})

const knowledgeSyncKmsPolicy = new PolicyStatement({
actions: [
"kms:Encrypt",
"kms:Decrypt",
"kms:ReEncrypt",
"kms:GenerateDataKey",
"kms:DescribeKey"
],
resources: [props.knowledgeSyncStateTableKmsKeyArn]
})

this.syncKnowledgeBasePolicy = new ManagedPolicy(this, "SyncKnowledgeBasePolicy", {
description: "Policy for SyncKnowledgeBase Lambda to trigger ingestion jobs",
statements: [
syncKnowledgeBaseBedrockPolicy,
syncKnowledgeBaseSSMPolicy,
knowledgeSyncDynamoDbPolicy,
knowledgeSyncKmsPolicy
]
})

//policy for the preprocessing lambda
Expand Down
4 changes: 0 additions & 4 deletions packages/cdk/resources/S3LambdaNotification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ export class S3LambdaNotification extends Construct {
const queue = new SimpleQueueService(this, `${props.stackName}-${queueName}`, {
stackName: props.stackName,
queueName: queueName,
batchDelay: 100,
functions: [
// Temporarily only trigger sync, as only one can run at once on SQS
// - if notifications is successful, sync won't run
// props.functions.notifyS3UploadFunction,
props.functions.syncKnowledgeBaseFunction
]
})
Expand Down
Loading
Loading