# Build Prisma Lambda Layer # Run this script before deploying to ensure the layer has the generated client $layerPath = "layers\prisma\nodejs" Write-Host "Building Prisma Lambda Layer..." -ForegroundColor Cyan # 1. Clean existing node_modules in layer Write-Host "Cleaning layer node_modules..." if (Test-Path "$layerPath\node_modules") { Remove-Item -Recurse -Force "$layerPath\node_modules" } # 2. Install dependencies in layer Write-Host "Installing layer dependencies..." Push-Location $layerPath npm install --omit=dev Pop-Location # 3. Generate Prisma client into the layer Write-Host "Generating Prisma client into layer..." # Set the output directory for Prisma client $env:PRISMA_GENERATE_DATAPROXY = "false" # Generate client - this creates .prisma/client npx prisma generate # 4. Copy .prisma/client to layer Write-Host "Copying generated Prisma client to layer..." $sourcePrisma = "node_modules\.prisma" $destPrisma = "$layerPath\node_modules\.prisma" if (Test-Path $sourcePrisma) { if (Test-Path $destPrisma) { Remove-Item -Recurse -Force $destPrisma } Copy-Item -Recurse $sourcePrisma $destPrisma Write-Host "Copied .prisma/client successfully!" -ForegroundColor Green } else { Write-Host "ERROR: .prisma folder not found. Run 'npx prisma generate' first." -ForegroundColor Red exit 1 } # 5. Show layer size Write-Host "`nLayer contents:" Get-ChildItem "$layerPath\node_modules" -Directory | Select-Object Name $layerSize = (Get-ChildItem "$layerPath\node_modules" -Recurse | Measure-Object -Property Length -Sum).Sum / 1MB Write-Host "`nTotal layer size: $([math]::Round($layerSize, 2)) MB" -ForegroundColor Yellow Write-Host "`nPrisma layer built successfully!" -ForegroundColor Green Write-Host "Run 'serverless deploy' to deploy with the updated layer."