{"record":{"id":"e6e52a9c5c8b608f","repo":"remotion-dev/remotion","slug":"lambda-function-unexpectedly-does-not-have-context","errorCode":null,"errorMessage":"Lambda function unexpectedly does not have context.invokedFunctionArn","messagePattern":"Lambda function unexpectedly does not have context\\.invokedFunctionArn","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/lambda/src/functions/index.ts","lineNumber":40,"sourceCode":"\nexport const routine = async (\n\tparams: ServerlessPayload<AwsProvider>,\n\tresponseStream: ResponseStream,\n\tcontext: LambdaRequestContext,\n): Promise<void> => {\n\tconst responseWriter = streamWriter(responseStream);\n\n\tconst buffered =\n\t\tparams.type === ServerlessRoutines.info ||\n\t\tparams.type === ServerlessRoutines.start ||\n\t\tparams.type === ServerlessRoutines.compositions;\n\n\ttry {\n\t\tprocess.env.__RESERVED_IS_INSIDE_REMOTION_LAMBDA = 'true';\n\t\tsetCurrentRequestId(context.awsRequestId);\n\t\tstopLeakDetection();\n\t\tif (!context?.invokedFunctionArn) {\n\t\t\tthrow new Error(\n\t\t\t\t'Lambda function unexpectedly does not have context.invokedFunctionArn',\n\t\t\t);\n\t\t}\n\n\t\tconst expectedBucketOwner = context.invokedFunctionArn.split(':')[4];\n\t\tif (!expectedBucketOwner) {\n\t\t\tthrow new Error('Expected current user ID');\n\t\t}\n\n\t\tawait innerHandler({\n\t\t\tparams,\n\t\t\tresponseWriter,\n\t\t\tcontext: {\n\t\t\t\trequestId: context.awsRequestId,\n\t\t\t\texpectedBucketOwner,\n\t\t\t\tgetRemainingTimeInMillis: () => context.getRemainingTimeInMillis(),\n\t\t\t},\n\t\t\tproviderSpecifics: LambdaClientInternals.awsImplementation,","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/remotion-dev/remotion/blob/b2f4e34732f3c6c222ea029413e22dc402218cd7/packages/lambda/src/functions/index.ts#L22-L58","documentation":"The Remotion Lambda handler (routine) runs inside AWS Lambda and expects context.invokedFunctionArn to identify the function's ARN, from which the AWS account ID is derived. If it is missing, the invocation did not come through a normal AWS Lambda runtime. The error guards against invoking the handler outside the real Lambda environment.","triggerScenarios":"Invoking the bundled Lambda handler function directly (e.g. locally, via a test harness, or a custom integration) with a context object lacking invokedFunctionArn, or with context null/undefined.","commonSituations":"Testing the handler locally with a hand-rolled context object, invoking through an event source that strips context, or calling the function via an unofficial runtime where AWS does not populate context.","solutions":["Only invoke the Remotion Lambda handler through the real AWS Lambda runtime (aws invoke lambda / console / SDK against the deployed function).","If testing locally, provide a context stub that includes invokedFunctionArn (and awsRequestId), e.g. invokedFunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:my-func'.","Verify you are running the built handler served by Remotion's deploy (npx remotion lambda functions deploy), not importing index.ts directly in a plain Node process."],"exampleFix":"// before (local test)\nawait routine(payload, {awsRequestId: 'req-1'}, ...);\n// after\nawait routine(payload, {\n  awsRequestId: 'req-1',\n  invokedFunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:remotion-render'\n}, ...);","handlingStrategy":"type-guard","validationCode":"function isLambdaContext(c: unknown): c is {awsRequestId: string; invokedFunctionArn: string} {\n  return typeof c === 'object' && c !== null &&\n    'invokedFunctionArn' in c && typeof (c as any).invokedFunctionArn === 'string' &&\n    (c as any).invokedFunctionArn.startsWith('arn:aws:lambda:');\n}","typeGuard":"function hasInvokedFunctionArn(ctx: unknown): ctx is {invokedFunctionArn: string; awsRequestId: string} {\n  return typeof (ctx as any)?.invokedFunctionArn === 'string' && (ctx as any).invokedFunctionArn.length > 0;\n}","tryCatchPattern":"try {\n  await routine(params, context, responseWriter);\n} catch (err) {\n  if ((err as Error).message.includes('invokedFunctionArn')) {\n    // handler was invoked outside real AWS Lambda; fix invocation\n  } else throw err;\n}","preventionTips":["Invoke Remotion Lambda handlers only through the deployed AWS Lambda function","Use realistic ARNs in any local test fixtures","Do not import the handler module directly into plain Node scripts"],"tags":["aws-lambda","context","arn","guard"],"backgroundTag":"missing-required-argument","analyzedSha":"b2f4e34732f3c6c222ea029413e22dc402218cd7","analyzedAt":"2026-09-09T13:27:51.281Z","contentChangedAt":"2026-09-09T13:27:51.281Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}