Skip to content

Commit 05b157e

Browse files
committed
fix layer
1 parent e3b2df2 commit 05b157e

File tree

6 files changed

+25
-20
lines changed

6 files changed

+25
-20
lines changed

.github/workflows/cdk_package_code.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ jobs:
6363
run: |
6464
poetry export --without-hashes --format=requirements.txt --with slackBotFunction > requirements_slackBotFunction
6565
poetry export --without-hashes --format=requirements.txt --with syncKnowledgeBaseFunction > requirements_syncKnowledgeBaseFunction
66-
pip3 install -r requirements_slackBotFunction -t packages/slackBotFunction/.dependencies/python
67-
pip3 install -r requirements_syncKnowledgeBaseFunction -t packages/syncKnowledgeBaseFunction/.dependencies/python
66+
pip3 install -r requirements_slackBotFunction -t .dependencies/slackBotFunction/python
67+
pip3 install -r requirements_syncKnowledgeBaseFunction -t .dependencies/syncKnowledgeBaseFunction/python
6868
6969
- name: 'Tar files'
7070
run: |

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,4 @@ cdk.out
3333
.requirements_slackBotFunction
3434
.requirements_syncKnowledgeBaseFunction
3535
.local_config/
36-
packages/slackBotFunction/.dependencies/
37-
packages/syncKnowledgeBaseFunction/.dependencies/
36+
.dependencies/

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ cdk-deploy: guard-STACK_NAME
100100
--context slackBotToken=$$SLACK_BOT_TOKEN \
101101
--context slackSigningSecret=$$SLACK_SIGNING_SECRET
102102
cdk-synth:
103-
mkdir -p packages/slackBotFunction/.dependencies
104-
mkdir -p packages/syncKnowledgeBaseFunction/.dependencies
103+
mkdir -p .dependencies/slackBotFunction
104+
mkdir -p .dependencies/SyncKnowledgeBaseFunction
105105
mkdir -p .local_config
106106
STACK_NAME=epsam \
107107
COMMIT_ID=undefined \

packages/cdk/constructs/LambdaFunction.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
Code
1919
} from "aws-cdk-lib/aws-lambda"
2020
import {CfnLogGroup, CfnSubscriptionFilter, LogGroup} from "aws-cdk-lib/aws-logs"
21-
import path from "path"
2221

2322
export interface LambdaFunctionProps {
2423
readonly stackName: string
@@ -29,6 +28,7 @@ export interface LambdaFunctionProps {
2928
readonly additionalPolicies?: Array<IManagedPolicy>
3029
readonly logRetentionInDays: number
3130
readonly logLevel: string
31+
readonly dependencyLocation?: string
3232
}
3333

3434
// Lambda Insights layer for enhanced monitoring
@@ -116,11 +116,15 @@ export class LambdaFunction extends Construct {
116116
managedPolicies: requiredPolicies
117117
})
118118

119-
const dependencyLayer = new LayerVersion(this, "DependencyLayer", {
120-
removalPolicy: RemovalPolicy.DESTROY,
121-
code: Code.fromAsset(path.join(props.packageBasePath, ".dependencies")),
122-
compatibleArchitectures: [Architecture.X86_64]
123-
})
119+
const layers = [insightsLambdaLayer]
120+
if (props.dependencyLocation) {
121+
const dependencyLayer = new LayerVersion(this, "DependencyLayer", {
122+
removalPolicy: RemovalPolicy.DESTROY,
123+
code: Code.fromAsset(props.dependencyLocation),
124+
compatibleArchitectures: [Architecture.X86_64]
125+
})
126+
layers.push(dependencyLayer)
127+
}
124128

125129
// Create Lambda function with Python runtime and monitoring
126130
const lambdaFunction = new LambdaFunctionResource(this, props.functionName, {
@@ -129,14 +133,14 @@ export class LambdaFunction extends Construct {
129133
timeout: Duration.seconds(50),
130134
architecture: Architecture.X86_64,
131135
handler: props.handler,
132-
code: Code.fromAsset(path.join(props.packageBasePath, "app")),
136+
code: Code.fromAsset(props.packageBasePath),
133137
role,
134138
environment: {
135139
...props.environmentVariables,
136140
POWERTOOLS_LOG_LEVEL: props.logLevel
137141
},
138142
logGroup,
139-
layers: [insightsLambdaLayer, dependencyLayer]
143+
layers: layers
140144
})
141145

142146
// Suppress CFN guard rules for Lambda function

packages/cdk/resources/Functions.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ export class Functions extends Construct {
4848
stackName: props.stackName,
4949
functionName: `${props.stackName}-SlackBotFunction`,
5050
packageBasePath: "packages/slackBotFunction",
51-
handler: "handler.handler",
51+
handler: "app.handler.handler",
5252
logRetentionInDays: props.logRetentionInDays,
5353
logLevel: props.logLevel,
5454
additionalPolicies: [props.slackBotManagedPolicy],
55+
dependencyLocation: ".dependencies/slackBotFunction",
5556
environmentVariables: {
5657
"RAG_MODEL_ID": RAG_MODEL_ID,
5758
"QUERY_REFORMULATION_MODEL_ID": QUERY_REFORMULATION_MODEL_ID,
@@ -77,9 +78,10 @@ export class Functions extends Construct {
7778
stackName: props.stackName,
7879
functionName: `${props.stackName}-SyncKnowledgeBaseFunction`,
7980
packageBasePath: "packages/syncKnowledgeBaseFunction",
80-
handler: "handler.handler",
81+
handler: "app.handler.handler",
8182
logRetentionInDays: props.logRetentionInDays,
8283
logLevel: props.logLevel,
84+
dependencyLocation: ".dependencies/syncKnowledgeBaseFunction",
8385
environmentVariables: {
8486
"KNOWLEDGEBASE_ID": props.knowledgeBaseId,
8587
"DATA_SOURCE_ID": props.dataSourceId

scripts/run_sync.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ echo "Generating config for ${EPSAM_CONFIG}"
6363
"$FIX_SCRIPT" "$EPSAM_CONFIG"
6464

6565
echo "Installing dependencies locally"
66-
poetry export --without-hashes --format=requirements.txt --with slackBotFunction > .requirements_slackBotFunction
67-
poetry export --without-hashes --format=requirements.txt --with syncKnowledgeBaseFunction > .requirements_syncKnowledgeBaseFunction
68-
pip3 install -r .requirements_slackBotFunction -t packages/slackBotFunction/.dependencies/python
69-
pip3 install -r .requirements_syncKnowledgeBaseFunction -t packages/syncKnowledgeBaseFunction/.dependencies/python
66+
poetry export --without-hashes --format=requirements.txt --with slackBotFunction > .dependencies/requirements_slackBotFunction
67+
poetry export --without-hashes --format=requirements.txt --with syncKnowledgeBaseFunction > .dependencies/requirements_syncKnowledgeBaseFunction
68+
pip3 install -r .dependencies/requirements_slackBotFunction -t .dependencies/slackBotFunction/python
69+
pip3 install -r .dependencies/requirements_syncKnowledgeBaseFunction -t .dependencies/syncKnowledgeBaseFunction/python
7070

7171
sync_epsam_app() {
7272
echo "Starting sync epsam CDK app"

0 commit comments

Comments
 (0)