{"record":{"id":"11cd35fbdee0f979","repo":"remotion-dev/remotion","slug":"lambda-functions-support-at-most-5-layers-includi","errorCode":null,"errorMessage":"Lambda functions support at most 5 Layers, including the Lambda Insights Layer.","messagePattern":"Lambda functions support at most 5 Layers, including the Lambda Insights Layer\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/lambda/src/shared/validate-custom-layer-arns.ts","lineNumber":43,"sourceCode":"\t\t\t\t'customLayerArns must be specified when deploying to AWS China regions because Remotion-hosted Layers are not available in the aws-cn partition.',\n\t\t\t);\n\t\t}\n\n\t\treturn;\n\t}\n\n\tif (!Array.isArray(customLayerArns) || customLayerArns.length === 0) {\n\t\tthrow new TypeError('customLayerArns must contain at least one Layer ARN.');\n\t}\n\n\tif (runtimePreference !== 'default') {\n\t\tthrow new Error(\n\t\t\t'customLayerArns cannot be combined with a non-default runtimePreference.',\n\t\t);\n\t}\n\n\tif (customLayerArns.length + (enableLambdaInsights ? 1 : 0) > 5) {\n\t\tthrow new Error(\n\t\t\t'Lambda functions support at most 5 Layers, including the Lambda Insights Layer.',\n\t\t);\n\t}\n\n\tconst seen = new Set<string>();\n\tfor (const layerArn of customLayerArns) {\n\t\tif (typeof layerArn !== 'string' || layerArn.length === 0) {\n\t\t\tthrow new TypeError(\n\t\t\t\t'Each customLayerArns entry must be a non-empty string.',\n\t\t\t);\n\t\t}\n\n\t\tconst match = layerArn.match(layerVersionArnRegex);\n\t\tif (!match) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`Invalid Lambda Layer version ARN: ${layerArn}. Expected arn:<partition>:lambda:<region>:<12-digit-account-id>:layer:<layer-name>:<numeric-version>.`,\n\t\t\t);\n\t\t}","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/remotion-dev/remotion/blob/10db9de07356446fb0edb3c3ae211369b693d18b/packages/lambda/src/shared/validate-custom-layer-arns.ts#L25-L61","documentation":"validateCustomLayerArns enforces the AWS hard limit of five Lambda layers per function. It counts your customLayerArns plus one extra slot if enableLambdaInsights is true, and throws as soon as the total would exceed five, so the deploy fails before hitting the AWS API limit.","triggerScenarios":"Calling deployFunction with six or more customLayerArns, or five customLayerArns together with `enableLambdaInsights: true`.","commonSituations":"Attaching many optional layers (chromium, fonts, ffmpeg, shared libs, monitoring agent) and forgetting the insights layer consumes a slot; consolidating layers after splitting a monolithic layer.","solutions":["Reduce customLayerArns to at most five entries, or four when enableLambdaInsights is true.","Merge several small layers into one ZIP (e.g. fonts + shared libraries) to free slots.","Disable enableLambdaInsights if you do not need the CloudWatch Lambda Insights layer."],"exampleFix":"// before\nawait deployFunction({\n  region: 'us-east-1',\n  enableLambdaInsights: true,\n  customLayerArns: [arn1, arn2, arn3, arn4, arn5], // 5 + insights = 6\n});\n\n// after\nawait deployFunction({\n  region: 'us-east-1',\n  enableLambdaInsights: true,\n  customLayerArns: [arn1, arn2, arn3, arnMergedFontsAndLibs], // 4 + insights = 5\n});","handlingStrategy":"validation","validationCode":"const total = customLayerArns.length + (enableLambdaInsights ? 1 : 0);\nif (total > 5) {\n  throw new Error(`Layer budget exceeded: ${total}/5 — merge layers or disable insights`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Model the 5-layer cap (minus one for insights) as a deploy-time invariant in your config builder.","Prefer few consolidated layers over many small ones."],"tags":["aws","lambda-layers","limits","deployfunction"],"backgroundTag":"aws-lambda-layer-limit","analyzedSha":"10db9de07356446fb0edb3c3ae211369b693d18b","analyzedAt":"2026-08-22T21:45:17.748Z","contentChangedAt":"2026-08-22T21:45:17.748Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}