The project is being developed along with "aws-cdk": "2.79.1"
and typescript
. The root directory is connect-backend
. There is a directory connect-backend/assets/lambda-layers/nodejs
. Currently I am installing npm packages inside this directory for the purpose of using them as lambda-layers. But deploy them to pipeline using Docker.
//package.json
{
"name": "lamda-layer",
"version": "1.0.0",
"dependencies": {
"@sparticuz/chromium": "^119.0.2",
"dayjs": "^1.11.11",
"handlebars": "^4.7.8",
"html-docx-js": "^0.3.1",
"node-html-parser": "^6.1.13",
"puppeteer-core": "^21.6.1",
"quoted-printable": "^1.0.1"
}
}
Inside the connect-backend-stack.ts
file, defined the layer path and name as below;
const lambdaLayer = new LambdaLayers(this, buildConfig, {
layerName: "AllInOneV2",
layerPath: "./assets/lambda-layers",
layerDescription : "Layer containing nodejs modules"
});
The construct-lambda-layers.ts
file;
import { Construct } from 'constructs';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { BuildConfig } from './build-config';
export interface LambdaLayerProps {
readonly layerName: string;
readonly layerPath: string;
readonly layerDescription: string;
}
export class LambdaLayers extends Construct {
public readonly lambdaLayer: lambda.LayerVersion;
constructor(scope: Construct, buildConfig: BuildConfig, props: LambdaLayerProps) {
super(scope, `${buildConfig.envPrefix}LambdaLayer-${props.layerName}`);
this.lambdaLayer = new lambda.LayerVersion(this, props.layerName, {
code: lambda.Code.fromAsset(props.layerPath, {
exclude: ['*', '!package.json', '!package-lock.json'],
bundling: {
image: lambda.Runtime.NODEJS_18_X.bundlingImage,
command: ['bash', '-c', 'mkdir /asset-output/nodejs && cd $_ &&'
+ 'cp -v /asset-input/nodejs/{package.json,package-lock.json} . &&'
+ 'npm ci'],
environment: { HOME: '/tmp/home' },
},
}),
compatibleArchitectures: [lambda.Architecture.X86_64, lambda.Architecture.ARM_64],
compatibleRuntimes: [lambda.Runtime.NODEJS_18_X],
description: props.layerDescription,
});
}
}
My problem is when some new npm packages are installed and tried to deploy, but I see only the previous npm packages in AWS lambda layers.
Here what I already tried to solve this issue, but could not solve the issue;
-
changed layerName in
layerName: "AllInOneV2",
-
deleted the already existing lambda layer file in aws and redeployed.
-
Changed local directory name
nodejs
tonodejs2
and redeployed -
Tried to change the bundling command to remove node modules first:
command: ['bash', '-c', 'mkdir /asset-output/nodejs && cd $_ &&' + 'rm -rf node_modules && '+ 'cp -v /asset-input/nodejs/{package.json,package-lock.json} . &&'+ 'npm ci'],
In the above last two cases (3 and 4), I got below error
Need help to solve this issue.
1