Add AWS Lambda Bundle Size Optimization Guide and update build scripts for Prisma layer

This commit is contained in:
paritosh18
2025-12-05 14:56:43 +05:30
parent b049146664
commit 20a931ab27
6 changed files with 571 additions and 63 deletions

View File

@@ -7,9 +7,9 @@ provider:
versionFunctions: false
memorySize: 512
# Apply Prisma layer to all functions
# Use the published layer version ARN (works for full deploy and `deploy function`)
# Reference the layer defined in this stack using CloudFormation Ref
layers:
- ${cf:${self:service}-${sls:stage}.PrismaLambdaLayerQualifiedArn}
- !Ref PrismaLambdaLayer
apiGateway:
binaryMediaTypes:
- '*/*'
@@ -68,14 +68,32 @@ build:
sourcemap: false
target: node20
platform: node
# Mark as external so they're not bundled into the JS
external:
# These are provided by the Prisma layer
- '@prisma/client'
- '@prisma/adapter-pg'
- '.prisma/client'
- '.prisma'
- 'pg'
- '@aws-sdk/*'
- '@smithy/*'
- '@aws-crypto/*'
# Exclude prevents npm install of these packages in the zip
exclude:
- 'aws-sdk'
- '@aws-sdk/*'
- '@smithy/*'
- '@aws-crypto/*'
- '@prisma/client'
- '@prisma/adapter-pg'
- '.prisma'
- '.prisma/client'
- 'pg'
exclude:
- 'aws-sdk'
- 'pg-*'
- 'postgres-*'
- 'pgpass'
- 'split2'
- 'xtend'
# Define layers
layers:
@@ -91,6 +109,8 @@ package:
individually: true
patterns:
- '!node_modules/**'
- '!node_modules/@prisma/**'
- '!node_modules/.prisma/**'
- '!**/*.test.js'
- '!**/*.spec.js'
- '!**/test/**'