Skip to content

Commit

Permalink
introduce layer dep
Browse files Browse the repository at this point in the history
  • Loading branch information
williamputraintan committed Mar 5, 2024
1 parent 1973b90 commit c9eb401
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This image will generate the node_modules needed for lambda and let
# the layer reference the output from this image

FROM public.ecr.aws/docker/library/node:20-alpine

WORKDIR /home/node/app

COPY package.json package.json
COPY yarn.lock yarn.lock
RUN yarn install --immutable

# making nodejs folder where as guided in the AWS lambda layer docs
RUN mkdir -p output/nodejs

# copy node_modules to that folder
RUN cp -r node_modules output/nodejs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,21 @@ export class PostgresManagerStack extends Stack {
props.clusterResourceIdParameterName
);

const dependencyLayer = new lambda.LayerVersion(this, 'DependenciesLayer', {
code: lambda.Code.fromDockerBuild(__dirname + '/../', {
cacheDisabled: true,
file: 'deploy/construct/layer/node_module.Dockerfile',
imagePath: 'home/node/app/output',
}),
compatibleArchitectures: [lambda.Architecture.ARM_64],
compatibleRuntimes: [lambda.Runtime.NODEJS_20_X],
});

const runtimeDependencies = Object.keys(package_json.dependencies);
const rdsLambdaProps: nodejs.NodejsFunctionProps = {
bundling: { nodeModules: runtimeDependencies },
layers: [dependencyLayer],
bundling: { externalModules: runtimeDependencies },
timeout: Duration.minutes(5),
depsLockFilePath: __dirname + '/../yarn.lock',
handler: 'handler',
runtime: lambda.Runtime.NODEJS_20_X,
architecture: lambda.Architecture.ARM_64,
Expand Down Expand Up @@ -101,9 +111,7 @@ export class PostgresManagerStack extends Stack {
new iam.PolicyStatement({
actions: ['secretsmanager:CreateSecret', 'secretsmanager:TagResource'],
effect: iam.Effect.ALLOW,
resources: [
`arn:aws:secretsmanager:ap-southeast-2:*:secret:*`,
],
resources: [`arn:aws:secretsmanager:ap-southeast-2:*:secret:*`],
}),
new iam.PolicyStatement({
actions: ['secretsmanager:GetRandomPassword'],
Expand Down

0 comments on commit c9eb401

Please sign in to comment.