1
    this.function = new cdk.aws_lambda.Function(this, 'PdfFunction', {
      runtime: cdk.aws_lambda.Runtime.NODEJS_20_X,
      handler: 'lambda.handler',
      code: cdk.aws_lambda.Code.fromAsset(path.join(__dirname, '../../'), {
        exclude: [
          'cdk/**',
          'cdk.out/**',
          'layer-build/**',
          'scripts/**',
          'tests/**',
          'lambda/**',
          '.git/**',
          'node_modules/**',
          '*.md',
        ],
        bundling: {
          image: cdk.aws_lambda.Runtime.NODEJS_20_X.bundlingImage,
          user: 'root',
          command: [
            'bash',
            '-lc',
            [
              'set -euo pipefail',
              // Install all deps (including dev) to build TypeScript
              'npm ci --no-audit --no-fund',
              // Build TS to dist/
              'npm run build',
              // Remove dev deps from node_modules to keep artifact small
              'npm prune --omit=dev',
              // Remove modules that are provided by the Lambda layer
              'rm -rf node_modules/@sparticuz node_modules/puppeteer-core node_modules/puppeteer-report node_modules/handlebars || true',
              // Output only what Lambda needs
              'mkdir -p /asset-output',
              'cp -r dist/* /asset-output/',
              'cp package.json /asset-output/',
              'cp -r node_modules /asset-output/',
            ].join(' && '),
          ],
        },
      }),
      timeout: cdk.Duration.seconds(30),
      memorySize: 2048, // Required for Chrome
      architecture: cdk.aws_lambda.Architecture.X86_64, // Required by layer
      layers: [documentGenerationLayer],
      environment: {
        NODE_ENV: props.stage === 'production' ? 'production' : 'development',
        STAGE: props.stage,
      },
    });

For immediate assistance, please email our customer support: [email protected]

Download RAW File