@remotion/lambda 4.0.256 → 4.0.258

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/dist/cli/get-aws-region.js +2 -1
  2. package/dist/cli/index.js +5 -4
  3. package/dist/shared/check-credentials.js +7 -6
  4. package/dist/shared/get-credentials.js +25 -23
  5. package/dist/shared/get-env-variable.d.ts +1 -0
  6. package/dist/shared/get-env-variable.js +15 -0
  7. package/dist/shared/get-service-client.js +16 -15
  8. package/dist/shared/is-likely-to-have-aws-profile.js +7 -1
  9. package/package.json +21 -21
  10. package/remotionlambda-arm64.zip +0 -0
  11. package/dist/api/__mocks__/clean-items.d.ts +0 -2
  12. package/dist/api/__mocks__/clean-items.js +0 -24
  13. package/dist/api/__mocks__/create-function.d.ts +0 -2
  14. package/dist/api/__mocks__/create-function.js +0 -21
  15. package/dist/api/__mocks__/delete-function.d.ts +0 -2
  16. package/dist/api/__mocks__/delete-function.js +0 -9
  17. package/dist/api/__mocks__/get-functions.d.ts +0 -2
  18. package/dist/api/__mocks__/get-functions.js +0 -9
  19. package/dist/api/__mocks__/upload-dir.d.ts +0 -3
  20. package/dist/api/__mocks__/upload-dir.js +0 -47
  21. package/dist/api/mock-functions.d.ts +0 -18
  22. package/dist/api/mock-functions.js +0 -36
  23. package/dist/cli/helpers/__mocks__/quit.d.ts +0 -1
  24. package/dist/cli/helpers/__mocks__/quit.js +0 -7
  25. package/dist/functions/chunk-optimization/plan-frame-ranges.d.ts +0 -7
  26. package/dist/functions/chunk-optimization/plan-frame-ranges.js +0 -17
  27. package/dist/functions/chunk-optimization/types.d.ts +0 -8
  28. package/dist/functions/chunk-optimization/types.js +0 -2
  29. package/dist/functions/helpers/__mocks__/get-browser-instance.d.ts +0 -3
  30. package/dist/functions/helpers/__mocks__/get-browser-instance.js +0 -12
  31. package/dist/functions/helpers/__mocks__/leak-detection.d.ts +0 -4
  32. package/dist/functions/helpers/__mocks__/leak-detection.js +0 -9
  33. package/dist/functions/helpers/__mocks__/timer.d.ts +0 -2
  34. package/dist/functions/helpers/__mocks__/timer.js +0 -10
  35. package/dist/functions/helpers/best-frames-per-lambda-param.d.ts +0 -1
  36. package/dist/functions/helpers/best-frames-per-lambda-param.js +0 -17
  37. package/dist/functions/helpers/calculate-chunk-times.d.ts +0 -5
  38. package/dist/functions/helpers/calculate-chunk-times.js +0 -29
  39. package/dist/functions/helpers/calculate-price-from-bucket.d.ts +0 -15
  40. package/dist/functions/helpers/calculate-price-from-bucket.js +0 -30
  41. package/dist/functions/helpers/can-concat-seamlessly.d.ts +0 -3
  42. package/dist/functions/helpers/can-concat-seamlessly.js +0 -17
  43. package/dist/functions/helpers/cleanup-props.d.ts +0 -8
  44. package/dist/functions/helpers/cleanup-props.js +0 -23
  45. package/dist/functions/helpers/concat-videos.d.ts +0 -23
  46. package/dist/functions/helpers/concat-videos.js +0 -54
  47. package/dist/functions/helpers/create-post-render-data.d.ts +0 -17
  48. package/dist/functions/helpers/create-post-render-data.js +0 -67
  49. package/dist/functions/helpers/find-output-file-in-bucket.d.ts +0 -14
  50. package/dist/functions/helpers/find-output-file-in-bucket.js +0 -38
  51. package/dist/functions/helpers/format-costs-info.d.ts +0 -2
  52. package/dist/functions/helpers/format-costs-info.js +0 -23
  53. package/dist/functions/helpers/get-overall-progress-s3.d.ts +0 -10
  54. package/dist/functions/helpers/get-overall-progress-s3.js +0 -24
  55. package/dist/functions/helpers/get-overall-progress.d.ts +0 -9
  56. package/dist/functions/helpers/get-overall-progress.js +0 -23
  57. package/dist/functions/helpers/get-progress.d.ts +0 -15
  58. package/dist/functions/helpers/get-progress.js +0 -254
  59. package/dist/functions/helpers/get-retry-stats.d.ts +0 -5
  60. package/dist/functions/helpers/get-retry-stats.js +0 -2
  61. package/dist/functions/helpers/inspect-errors.d.ts +0 -4
  62. package/dist/functions/helpers/inspect-errors.js +0 -39
  63. package/dist/functions/helpers/is-warm.d.ts +0 -2
  64. package/dist/functions/helpers/is-warm.js +0 -10
  65. package/dist/functions/helpers/leak-detection.d.ts +0 -4
  66. package/dist/functions/helpers/leak-detection.js +0 -40
  67. package/dist/functions/helpers/make-timeout-error.d.ts +0 -10
  68. package/dist/functions/helpers/make-timeout-error.js +0 -31
  69. package/dist/functions/helpers/make-timeout-message.d.ts +0 -10
  70. package/dist/functions/helpers/make-timeout-message.js +0 -75
  71. package/dist/functions/helpers/merge-chunks.d.ts +0 -36
  72. package/dist/functions/helpers/merge-chunks.js +0 -84
  73. package/dist/functions/helpers/min-max.d.ts +0 -2
  74. package/dist/functions/helpers/min-max.js +0 -33
  75. package/dist/functions/helpers/on-downloads-logger.d.ts +0 -2
  76. package/dist/functions/helpers/on-downloads-logger.js +0 -29
  77. package/dist/functions/helpers/overall-render-progress.d.ts +0 -59
  78. package/dist/functions/helpers/overall-render-progress.js +0 -180
  79. package/dist/functions/helpers/print-concurrency-curve.d.ts +0 -1
  80. package/dist/functions/helpers/print-concurrency-curve.js +0 -8
  81. package/dist/functions/helpers/print-logging-helper.d.ts +0 -4
  82. package/dist/functions/helpers/print-logging-helper.js +0 -12
  83. package/dist/functions/helpers/render-has-audio-video.d.ts +0 -6
  84. package/dist/functions/helpers/render-has-audio-video.js +0 -21
  85. package/dist/functions/helpers/request-context.d.ts +0 -5
  86. package/dist/functions/helpers/request-context.js +0 -2
  87. package/dist/functions/helpers/stream-renderer.d.ts +0 -17
  88. package/dist/functions/helpers/stream-renderer.js +0 -148
  89. package/dist/functions/launch.d.ts +0 -10
  90. package/dist/functions/launch.js +0 -595
  91. package/dist/functions/progress.d.ts +0 -11
  92. package/dist/functions/progress.js +0 -51
  93. package/dist/functions/renderer.d.ts +0 -17
  94. package/dist/functions/renderer.js +0 -341
  95. package/dist/functions/start.d.ts +0 -13
  96. package/dist/functions/start.js +0 -112
  97. package/dist/functions/still.d.ts +0 -19
  98. package/dist/functions/still.js +0 -329
  99. package/dist/shared/__mocks__/aws-clients.d.ts +0 -2
  100. package/dist/shared/__mocks__/aws-clients.js +0 -62
  101. package/dist/shared/__mocks__/bundle-site.d.ts +0 -2
  102. package/dist/shared/__mocks__/bundle-site.js +0 -32
  103. package/dist/shared/__mocks__/check-credentials.d.ts +0 -1
  104. package/dist/shared/__mocks__/check-credentials.js +0 -5
  105. package/dist/shared/__mocks__/get-account-id.d.ts +0 -2
  106. package/dist/shared/__mocks__/get-account-id.js +0 -11
  107. package/dist/shared/__mocks__/read-dir.d.ts +0 -2
  108. package/dist/shared/__mocks__/read-dir.js +0 -13
  109. package/dist/shared/call-lambda.d.ts +0 -16
  110. package/dist/shared/call-lambda.js +0 -149
  111. package/dist/shared/cleanup-serialized-input-props.d.ts +0 -14
  112. package/dist/shared/cleanup-serialized-input-props.js +0 -34
  113. package/dist/shared/docs-url.d.ts +0 -1
  114. package/dist/shared/docs-url.js +0 -4
  115. package/dist/shared/get-most-expensive-chunks.d.ts +0 -8
  116. package/dist/shared/get-most-expensive-chunks.js +0 -28
  117. package/dist/shared/invoke-webhook.d.ts +0 -48
  118. package/dist/shared/invoke-webhook.js +0 -140
  119. package/dist/shared/parse-lambda-timings-key.d.ts +0 -5
  120. package/dist/shared/parse-lambda-timings-key.js +0 -2
  121. package/dist/shared/return-values.d.ts +0 -16
  122. package/dist/shared/return-values.js +0 -2
  123. package/dist/shared/stackback.d.ts +0 -6
  124. package/dist/shared/stackback.js +0 -59
  125. package/dist/shared/validate-download-behavior.d.ts +0 -1
  126. package/dist/shared/validate-download-behavior.js +0 -21
  127. package/dist/shared/validate-frames-per-lambda.d.ts +0 -4
  128. package/dist/shared/validate-frames-per-lambda.js +0 -29
  129. package/dist/shared/validate-privacy.d.ts +0 -2
  130. package/dist/shared/validate-privacy.js +0 -14
  131. package/dist/shared/validate.d.ts +0 -4
  132. package/dist/shared/validate.js +0 -8
  133. package/dist/shared/why-is-node-running.d.ts +0 -15
  134. package/dist/shared/why-is-node-running.js +0 -88
@@ -1,595 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.launchHandler = void 0;
4
- const renderer_1 = require("@remotion/renderer");
5
- const serverless_1 = require("@remotion/serverless");
6
- const client_1 = require("@remotion/serverless/client");
7
- const fs_1 = require("fs");
8
- const path_1 = require("path");
9
- const version_1 = require("remotion/version");
10
- const constants_1 = require("../shared/constants");
11
- const docs_url_1 = require("../shared/docs-url");
12
- const invoke_webhook_1 = require("../shared/invoke-webhook");
13
- const validate_1 = require("../shared/validate");
14
- const validate_frames_per_lambda_1 = require("../shared/validate-frames-per-lambda");
15
- const validate_privacy_1 = require("../shared/validate-privacy");
16
- const plan_frame_ranges_1 = require("./chunk-optimization/plan-frame-ranges");
17
- const best_frames_per_lambda_param_1 = require("./helpers/best-frames-per-lambda-param");
18
- const cleanup_props_1 = require("./helpers/cleanup-props");
19
- const find_output_file_in_bucket_1 = require("./helpers/find-output-file-in-bucket");
20
- const merge_chunks_1 = require("./helpers/merge-chunks");
21
- const overall_render_progress_1 = require("./helpers/overall-render-progress");
22
- const stream_renderer_1 = require("./helpers/stream-renderer");
23
- const timer_1 = require("./helpers/timer");
24
- const innerLaunchHandler = async ({ functionName, params, options, overallProgress, registerCleanupTask, providerSpecifics, }) => {
25
- var _a, _b, _c, _d, _e, _f, _g;
26
- if (params.type !== client_1.ServerlessRoutines.launch) {
27
- throw new Error('Expected launch type');
28
- }
29
- const startedDate = Date.now();
30
- const browserInstance = (0, serverless_1.getBrowserInstance)({
31
- logLevel: params.logLevel,
32
- indent: false,
33
- chromiumOptions: params.chromiumOptions,
34
- providerSpecifics,
35
- });
36
- const inputPropsPromise = (0, client_1.decompressInputProps)({
37
- bucketName: params.bucketName,
38
- expectedBucketOwner: options.expectedBucketOwner,
39
- region: providerSpecifics.getCurrentRegionInFunction(),
40
- serialized: params.inputProps,
41
- propsType: 'input-props',
42
- providerSpecifics,
43
- forcePathStyle: params.forcePathStyle,
44
- });
45
- const logOptions = {
46
- indent: false,
47
- logLevel: params.logLevel,
48
- };
49
- const serializedInputPropsWithCustomSchema = await inputPropsPromise;
50
- renderer_1.RenderInternals.Log.info(logOptions, 'Waiting for browser to be ready:', serializedInputPropsWithCustomSchema);
51
- const { instance } = await browserInstance;
52
- renderer_1.RenderInternals.Log.info(logOptions, 'Validating composition, input props:', serializedInputPropsWithCustomSchema);
53
- const startTime = Date.now();
54
- const comp = await (0, serverless_1.validateComposition)({
55
- serveUrl: params.serveUrl,
56
- composition: params.composition,
57
- browserInstance: instance,
58
- serializedInputPropsWithCustomSchema,
59
- envVariables: (_a = params.envVariables) !== null && _a !== void 0 ? _a : {},
60
- timeoutInMilliseconds: params.timeoutInMilliseconds,
61
- chromiumOptions: params.chromiumOptions,
62
- port: null,
63
- forceHeight: params.forceHeight,
64
- forceWidth: params.forceWidth,
65
- logLevel: params.logLevel,
66
- server: undefined,
67
- offthreadVideoCacheSizeInBytes: params.offthreadVideoCacheSizeInBytes,
68
- onBrowserDownload: () => {
69
- throw new Error('Should not download a browser in Lambda');
70
- },
71
- onServeUrlVisited: () => {
72
- overallProgress.setServeUrlOpened(Date.now());
73
- },
74
- providerSpecifics,
75
- });
76
- overallProgress.setCompositionValidated(Date.now());
77
- renderer_1.RenderInternals.Log.info(logOptions, 'Composition validated, resolved props', comp.props);
78
- (0, validate_1.validateDurationInFrames)(comp.durationInFrames, {
79
- component: 'passed to a Lambda render',
80
- allowFloats: false,
81
- });
82
- (0, validate_1.validateFps)(comp.fps, 'passed to a Lambda render', false);
83
- (0, validate_1.validateDimension)(comp.height, 'height', 'passed to a Lambda render');
84
- (0, validate_1.validateDimension)(comp.width, 'width', 'passed to a Lambda render');
85
- renderer_1.RenderInternals.validateBitrate(params.audioBitrate, 'audioBitrate');
86
- renderer_1.RenderInternals.validateBitrate(params.videoBitrate, 'videoBitrate');
87
- renderer_1.RenderInternals.validateConcurrency({
88
- value: params.concurrencyPerLambda,
89
- setting: 'concurrencyPerLambda',
90
- checkIfValidForCurrentMachine: true,
91
- });
92
- const realFrameRange = renderer_1.RenderInternals.getRealFrameRange(comp.durationInFrames, params.frameRange);
93
- const frameCount = renderer_1.RenderInternals.getFramesToRender(realFrameRange, params.everyNthFrame);
94
- const framesPerLambda = (_b = params.framesPerLambda) !== null && _b !== void 0 ? _b : (0, best_frames_per_lambda_param_1.bestFramesPerLambdaParam)(frameCount.length);
95
- (0, validate_frames_per_lambda_1.validateFramesPerLambda)({
96
- framesPerLambda,
97
- durationInFrames: frameCount.length,
98
- });
99
- (0, serverless_1.validateOutname)({
100
- outName: params.outName,
101
- codec: params.codec,
102
- audioCodecSetting: params.audioCodec,
103
- separateAudioTo: null,
104
- });
105
- (0, validate_privacy_1.validatePrivacy)(params.privacy, true);
106
- renderer_1.RenderInternals.validatePuppeteerTimeout(params.timeoutInMilliseconds);
107
- const { chunks } = (0, plan_frame_ranges_1.planFrameRanges)({
108
- framesPerLambda,
109
- frameRange: realFrameRange,
110
- everyNthFrame: params.everyNthFrame,
111
- });
112
- if (chunks.length > constants_1.MAX_FUNCTIONS_PER_RENDER) {
113
- throw new Error(`Too many functions: This render would cause ${chunks.length} functions to spawn. We limit this amount to ${constants_1.MAX_FUNCTIONS_PER_RENDER} functions as more would result in diminishing returns. Values set: frameCount = ${frameCount.length}, framesPerLambda=${framesPerLambda}. See ${docs_url_1.DOCS_URL}/docs/lambda/concurrency#too-many-functions for help.`);
114
- }
115
- overallProgress.setExpectedChunks(chunks.length);
116
- const sortedChunks = chunks.slice().sort((a, b) => a[0] - b[0]);
117
- const serializedResolved = (0, client_1.serializeOrThrow)(comp.props, 'resolved-props');
118
- const needsToUpload = (0, client_1.getNeedsToUpload)('video-or-audio', [
119
- serializedResolved.length,
120
- params.inputProps.type === 'bucket-url'
121
- ? params.inputProps.hash.length
122
- : params.inputProps.payload.length,
123
- JSON.stringify(params.envVariables).length,
124
- ]);
125
- const serializedResolvedProps = await (0, client_1.compressInputProps)({
126
- propsType: 'resolved-props',
127
- region: providerSpecifics.getCurrentRegionInFunction(),
128
- stringifiedInputProps: serializedResolved,
129
- userSpecifiedBucketName: params.bucketName,
130
- needsToUpload,
131
- providerSpecifics,
132
- forcePathStyle: params.forcePathStyle,
133
- });
134
- registerCleanupTask(() => {
135
- return (0, cleanup_props_1.cleanupProps)({
136
- serializedResolvedProps,
137
- inputProps: params.inputProps,
138
- providerSpecifics,
139
- forcePathStyle: params.forcePathStyle,
140
- });
141
- });
142
- const fps = comp.fps / params.everyNthFrame;
143
- // If for 150 functions, we stream every frame, we DDos ourselves.
144
- // Throttling a bit, allowing more progress if there is lower concurrency.
145
- const progressEveryNthFrame = Math.ceil(chunks.length / 15);
146
- const lambdaPayloads = chunks.map((chunkPayload) => {
147
- var _a;
148
- const payload = {
149
- type: client_1.ServerlessRoutines.renderer,
150
- frameRange: chunkPayload,
151
- serveUrl: params.serveUrl,
152
- chunk: sortedChunks.indexOf(chunkPayload),
153
- composition: params.composition,
154
- fps: comp.fps,
155
- height: comp.height,
156
- width: comp.width,
157
- durationInFrames: comp.durationInFrames,
158
- bucketName: params.bucketName,
159
- retriesLeft: params.maxRetries,
160
- inputProps: params.inputProps,
161
- renderId: params.renderId,
162
- imageFormat: params.imageFormat,
163
- codec: params.codec,
164
- crf: params.crf,
165
- envVariables: params.envVariables,
166
- pixelFormat: params.pixelFormat,
167
- proResProfile: params.proResProfile,
168
- x264Preset: params.x264Preset,
169
- jpegQuality: params.jpegQuality,
170
- privacy: params.privacy,
171
- logLevel: (_a = params.logLevel) !== null && _a !== void 0 ? _a : 'info',
172
- attempt: 1,
173
- timeoutInMilliseconds: params.timeoutInMilliseconds,
174
- chromiumOptions: params.chromiumOptions,
175
- scale: params.scale,
176
- everyNthFrame: params.everyNthFrame,
177
- concurrencyPerLambda: params.concurrencyPerLambda,
178
- muted: params.muted,
179
- audioBitrate: params.audioBitrate,
180
- videoBitrate: params.videoBitrate,
181
- encodingMaxRate: params.encodingMaxRate,
182
- encodingBufferSize: params.encodingBufferSize,
183
- launchFunctionConfig: {
184
- version: version_1.VERSION,
185
- },
186
- resolvedProps: serializedResolvedProps,
187
- offthreadVideoCacheSizeInBytes: params.offthreadVideoCacheSizeInBytes,
188
- deleteAfter: params.deleteAfter,
189
- colorSpace: params.colorSpace,
190
- preferLossless: params.preferLossless,
191
- compositionStart: realFrameRange[0],
192
- framesPerLambda,
193
- progressEveryNthFrame,
194
- forcePathStyle: params.forcePathStyle,
195
- metadata: params.metadata,
196
- };
197
- return payload;
198
- });
199
- renderer_1.RenderInternals.Log.info(logOptions, 'Render plan: ', chunks.map((c, i) => `Chunk ${i} (Frames ${c[0]} - ${c[1]})`).join(', '));
200
- const renderMetadata = {
201
- startedDate,
202
- totalChunks: chunks.length,
203
- estimatedTotalLambdaInvokations: [
204
- // Direct invokations
205
- chunks.length,
206
- // This function
207
- 1,
208
- ].reduce((a, b) => a + b, 0),
209
- estimatedRenderLambdaInvokations: chunks.length,
210
- compositionId: comp.id,
211
- siteId: params.serveUrl,
212
- codec: params.codec,
213
- type: 'video',
214
- imageFormat: params.imageFormat,
215
- inputProps: params.inputProps,
216
- lambdaVersion: version_1.VERSION,
217
- framesPerLambda,
218
- memorySizeInMb: Number(process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE),
219
- region: providerSpecifics.getCurrentRegionInFunction(),
220
- renderId: params.renderId,
221
- outName: (_c = params.outName) !== null && _c !== void 0 ? _c : undefined,
222
- privacy: params.privacy,
223
- everyNthFrame: params.everyNthFrame,
224
- frameRange: realFrameRange,
225
- audioCodec: params.audioCodec,
226
- deleteAfter: params.deleteAfter,
227
- numberOfGifLoops: params.numberOfGifLoops,
228
- downloadBehavior: params.downloadBehavior,
229
- audioBitrate: params.audioBitrate,
230
- muted: params.muted,
231
- metadata: params.metadata,
232
- functionName: process.env.AWS_LAMBDA_FUNCTION_NAME,
233
- dimensions: {
234
- width: comp.width * ((_d = params.scale) !== null && _d !== void 0 ? _d : 1),
235
- height: comp.height * ((_e = params.scale) !== null && _e !== void 0 ? _e : 1),
236
- },
237
- };
238
- const { key, renderBucketName, customCredentials } = (0, client_1.getExpectedOutName)(renderMetadata, params.bucketName, typeof params.outName === 'string' || typeof params.outName === 'undefined'
239
- ? null
240
- : ((_g = (_f = params.outName) === null || _f === void 0 ? void 0 : _f.s3OutputProvider) !== null && _g !== void 0 ? _g : null));
241
- if (!params.overwrite) {
242
- const findOutputFile = (0, timer_1.timer)('Checking if output file already exists', params.logLevel);
243
- const output = await (0, find_output_file_in_bucket_1.findOutputFileInBucket)({
244
- bucketName: params.bucketName,
245
- customCredentials,
246
- renderMetadata,
247
- region: providerSpecifics.getCurrentRegionInFunction(),
248
- currentRegion: providerSpecifics.getCurrentRegionInFunction(),
249
- providerSpecifics,
250
- forcePathStyle: params.forcePathStyle,
251
- });
252
- if (output) {
253
- throw new TypeError(`Output file "${key}" in bucket "${renderBucketName}" in region "${providerSpecifics.getCurrentRegionInFunction()}" already exists. Delete it before re-rendering, or set the 'overwrite' option in renderMediaOnLambda() to overwrite it."`);
254
- }
255
- findOutputFile.end();
256
- }
257
- overallProgress.setRenderMetadata(renderMetadata);
258
- const outdir = (0, path_1.join)(renderer_1.RenderInternals.tmpDir(constants_1.CONCAT_FOLDER_TOKEN), 'bucket');
259
- if ((0, fs_1.existsSync)(outdir)) {
260
- (0, fs_1.rmSync)(outdir, {
261
- recursive: true,
262
- });
263
- }
264
- (0, fs_1.mkdirSync)(outdir);
265
- const files = [];
266
- const onArtifact = (artifact) => {
267
- if (overallProgress
268
- .getReceivedArtifacts()
269
- .find((a) => a.filename === artifact.filename)) {
270
- return { alreadyExisted: true };
271
- }
272
- const region = providerSpecifics.getCurrentRegionInFunction();
273
- const storageKey = (0, client_1.artifactName)(renderMetadata.renderId, artifact.filename);
274
- const start = Date.now();
275
- renderer_1.RenderInternals.Log.info({ indent: false, logLevel: params.logLevel }, 'Writing artifact ' + artifact.filename + ' to S3');
276
- providerSpecifics
277
- .writeFile({
278
- bucketName: renderBucketName,
279
- key: storageKey,
280
- body: artifact.content,
281
- region,
282
- privacy: params.privacy,
283
- expectedBucketOwner: options.expectedBucketOwner,
284
- downloadBehavior: params.downloadBehavior,
285
- customCredentials,
286
- forcePathStyle: params.forcePathStyle,
287
- })
288
- .then(() => {
289
- renderer_1.RenderInternals.Log.info({ indent: false, logLevel: params.logLevel }, `Wrote artifact to S3 in ${Date.now() - start}ms`);
290
- overallProgress.addReceivedArtifact(providerSpecifics.makeArtifactWithDetails({
291
- region,
292
- renderBucketName,
293
- storageKey,
294
- artifact,
295
- }));
296
- })
297
- .catch((err) => {
298
- overallProgress.addErrorWithoutUpload({
299
- type: 'artifact',
300
- message: err.message,
301
- name: err.name,
302
- stack: err.stack,
303
- tmpDir: null,
304
- frame: artifact.frame,
305
- chunk: null,
306
- isFatal: false,
307
- attempt: 1,
308
- willRetry: false,
309
- totalAttempts: 1,
310
- });
311
- overallProgress.upload();
312
- renderer_1.RenderInternals.Log.error({ indent: false, logLevel: params.logLevel }, 'Failed to write artifact to S3', err);
313
- });
314
- return { alreadyExisted: false };
315
- };
316
- await Promise.all(lambdaPayloads.map(async (payload) => {
317
- await (0, stream_renderer_1.streamRendererFunctionWithRetry)({
318
- files,
319
- functionName,
320
- outdir,
321
- overallProgress,
322
- payload,
323
- logLevel: params.logLevel,
324
- onArtifact,
325
- providerSpecifics,
326
- });
327
- }));
328
- const postRenderData = await (0, merge_chunks_1.mergeChunksAndFinishRender)({
329
- bucketName: params.bucketName,
330
- renderId: params.renderId,
331
- expectedBucketOwner: options.expectedBucketOwner,
332
- numberOfFrames: frameCount.length,
333
- audioCodec: params.audioCodec,
334
- chunkCount: chunks.length,
335
- codec: params.codec,
336
- customCredentials,
337
- downloadBehavior: params.downloadBehavior,
338
- fps,
339
- key,
340
- numberOfGifLoops: params.numberOfGifLoops,
341
- privacy: params.privacy,
342
- renderBucketName,
343
- inputProps: params.inputProps,
344
- serializedResolvedProps,
345
- renderMetadata,
346
- audioBitrate: params.audioBitrate,
347
- logLevel: params.logLevel,
348
- framesPerLambda,
349
- binariesDirectory: null,
350
- preferLossless: params.preferLossless,
351
- compositionStart: realFrameRange[0],
352
- outdir,
353
- files: files.sort(),
354
- overallProgress,
355
- startTime,
356
- providerSpecifics,
357
- forcePathStyle: params.forcePathStyle,
358
- });
359
- return postRenderData;
360
- };
361
- const launchHandler = async (params, options, providerSpecifics) => {
362
- var _a, _b, _c;
363
- if (params.type !== client_1.ServerlessRoutines.launch) {
364
- throw new Error('Expected launch type');
365
- }
366
- const functionName = (_a = params.rendererFunctionName) !== null && _a !== void 0 ? _a : process.env.AWS_LAMBDA_FUNCTION_NAME;
367
- const logOptions = {
368
- indent: false,
369
- logLevel: params.logLevel,
370
- };
371
- const cleanupTasks = [];
372
- const registerCleanupTask = (task) => {
373
- cleanupTasks.push(task);
374
- };
375
- const runCleanupTasks = () => {
376
- const prom = Promise.all(cleanupTasks)
377
- .then(() => {
378
- renderer_1.RenderInternals.Log.info({ indent: false, logLevel: params.logLevel }, 'Ran cleanup tasks');
379
- })
380
- .catch((err) => {
381
- renderer_1.RenderInternals.Log.error({ indent: false, logLevel: params.logLevel }, 'Failed to run cleanup tasks:', err);
382
- });
383
- cleanupTasks.length = 0;
384
- return prom;
385
- };
386
- const onTimeout = async () => {
387
- var _a;
388
- renderer_1.RenderInternals.Log.error({ indent: false, logLevel: params.logLevel }, 'Function is about to time out. Can not finish render.');
389
- // @ts-expect-error - We are adding a listener to a global variable
390
- if (globalThis._dumpUnreleasedBuffers) {
391
- // @ts-expect-error - We are adding a listener to a global variable
392
- globalThis._dumpUnreleasedBuffers.emit('dump-unreleased-buffers');
393
- }
394
- runCleanupTasks();
395
- if (!params.webhook) {
396
- renderer_1.RenderInternals.Log.verbose({
397
- indent: false,
398
- logLevel: params.logLevel,
399
- }, 'No webhook specified.');
400
- return;
401
- }
402
- if (webhookInvoked) {
403
- renderer_1.RenderInternals.Log.verbose({
404
- indent: false,
405
- logLevel: params.logLevel,
406
- }, 'Webhook already invoked. Not invoking again.');
407
- return;
408
- }
409
- try {
410
- await (0, invoke_webhook_1.invokeWebhook)({
411
- url: params.webhook.url,
412
- secret: params.webhook.secret,
413
- payload: {
414
- type: 'timeout',
415
- renderId: params.renderId,
416
- expectedBucketOwner: options.expectedBucketOwner,
417
- bucketName: params.bucketName,
418
- customData: (_a = params.webhook.customData) !== null && _a !== void 0 ? _a : null,
419
- },
420
- redirectsSoFar: 0,
421
- }, params.logLevel);
422
- renderer_1.RenderInternals.Log.verbose({
423
- indent: false,
424
- logLevel: params.logLevel,
425
- }, 'Successfully invoked timeout webhook.', params.webhook.url);
426
- webhookInvoked = true;
427
- }
428
- catch (err) {
429
- if (process.env.NODE_ENV === 'test') {
430
- throw err;
431
- }
432
- renderer_1.RenderInternals.Log.error({ indent: false, logLevel: params.logLevel }, 'Failed to invoke webhook:');
433
- renderer_1.RenderInternals.Log.error({ indent: false, logLevel: params.logLevel }, err);
434
- overallProgress.addErrorWithoutUpload({
435
- type: 'webhook',
436
- message: err.message,
437
- name: err.name,
438
- stack: err.stack,
439
- tmpDir: null,
440
- frame: 0,
441
- chunk: 0,
442
- isFatal: false,
443
- attempt: 1,
444
- willRetry: false,
445
- totalAttempts: 1,
446
- });
447
- overallProgress.upload();
448
- }
449
- };
450
- let webhookInvoked = false;
451
- const webhookDueToTimeout = setTimeout(onTimeout, Math.max(options.getRemainingTimeInMillis() - 1000, 1000));
452
- renderer_1.RenderInternals.Log.info(logOptions, `Function has ${Math.max(options.getRemainingTimeInMillis() - 1000, 1000)} before it times out`);
453
- const overallProgress = (0, overall_render_progress_1.makeOverallRenderProgress)({
454
- renderId: params.renderId,
455
- bucketName: params.bucketName,
456
- expectedBucketOwner: options.expectedBucketOwner,
457
- region: providerSpecifics.getCurrentRegionInFunction(),
458
- timeoutTimestamp: options.getRemainingTimeInMillis() + Date.now(),
459
- logLevel: params.logLevel,
460
- providerSpecifics,
461
- forcePathStyle: params.forcePathStyle,
462
- });
463
- try {
464
- const postRenderData = await innerLaunchHandler({
465
- functionName,
466
- params,
467
- options,
468
- overallProgress,
469
- registerCleanupTask,
470
- providerSpecifics,
471
- });
472
- clearTimeout(webhookDueToTimeout);
473
- if (!params.webhook || webhookInvoked) {
474
- return {
475
- type: 'success',
476
- };
477
- }
478
- try {
479
- await (0, invoke_webhook_1.invokeWebhook)({
480
- url: params.webhook.url,
481
- secret: params.webhook.secret,
482
- payload: {
483
- type: 'success',
484
- renderId: params.renderId,
485
- expectedBucketOwner: options.expectedBucketOwner,
486
- bucketName: params.bucketName,
487
- customData: (_b = params.webhook.customData) !== null && _b !== void 0 ? _b : null,
488
- outputUrl: postRenderData.outputFile,
489
- lambdaErrors: postRenderData.errors,
490
- outputFile: postRenderData.outputFile,
491
- timeToFinish: postRenderData.timeToFinish,
492
- costs: postRenderData.cost,
493
- },
494
- redirectsSoFar: 0,
495
- }, params.logLevel);
496
- webhookInvoked = true;
497
- }
498
- catch (err) {
499
- if (process.env.NODE_ENV === 'test') {
500
- throw err;
501
- }
502
- overallProgress.addErrorWithoutUpload({
503
- type: 'webhook',
504
- message: err.message,
505
- name: err.name,
506
- stack: err.stack,
507
- tmpDir: null,
508
- frame: 0,
509
- chunk: 0,
510
- isFatal: false,
511
- attempt: 1,
512
- willRetry: false,
513
- totalAttempts: 1,
514
- });
515
- overallProgress.upload();
516
- renderer_1.RenderInternals.Log.error({ indent: false, logLevel: params.logLevel }, 'Failed to invoke webhook:');
517
- renderer_1.RenderInternals.Log.error({ indent: false, logLevel: params.logLevel }, err);
518
- }
519
- runCleanupTasks();
520
- return {
521
- type: 'success',
522
- };
523
- }
524
- catch (err) {
525
- if (process.env.NODE_ENV === 'test') {
526
- throw err;
527
- }
528
- renderer_1.RenderInternals.Log.error({ indent: false, logLevel: params.logLevel }, 'Error occurred', err);
529
- overallProgress.addErrorWithoutUpload({
530
- chunk: null,
531
- frame: null,
532
- name: err.name,
533
- stack: err.stack,
534
- type: 'stitcher',
535
- isFatal: true,
536
- tmpDir: (0, serverless_1.getTmpDirStateIfENoSp)(err.stack, providerSpecifics),
537
- attempt: 1,
538
- totalAttempts: 1,
539
- willRetry: false,
540
- message: err.message,
541
- });
542
- await overallProgress.upload();
543
- runCleanupTasks();
544
- renderer_1.RenderInternals.Log.error({ indent: false, logLevel: params.logLevel }, 'Wrote error to S3');
545
- clearTimeout(webhookDueToTimeout);
546
- if (params.webhook && !webhookInvoked) {
547
- try {
548
- await (0, invoke_webhook_1.invokeWebhook)({
549
- url: params.webhook.url,
550
- secret: params.webhook.secret,
551
- payload: {
552
- type: 'error',
553
- renderId: params.renderId,
554
- expectedBucketOwner: options.expectedBucketOwner,
555
- bucketName: params.bucketName,
556
- customData: (_c = params.webhook.customData) !== null && _c !== void 0 ? _c : null,
557
- errors: [err].map((e) => ({
558
- message: e.message,
559
- name: e.name,
560
- stack: e.stack,
561
- })),
562
- },
563
- redirectsSoFar: 0,
564
- }, params.logLevel);
565
- webhookInvoked = true;
566
- }
567
- catch (error) {
568
- if (process.env.NODE_ENV === 'test') {
569
- throw error;
570
- }
571
- overallProgress.addErrorWithoutUpload({
572
- type: 'webhook',
573
- message: err.message,
574
- name: err.name,
575
- stack: err.stack,
576
- tmpDir: null,
577
- frame: 0,
578
- chunk: 0,
579
- isFatal: false,
580
- attempt: 1,
581
- willRetry: false,
582
- totalAttempts: 1,
583
- });
584
- overallProgress.upload();
585
- renderer_1.RenderInternals.Log.error({ indent: false, logLevel: params.logLevel }, 'Failed to invoke webhook:');
586
- renderer_1.RenderInternals.Log.error({ indent: false, logLevel: params.logLevel }, error);
587
- }
588
- }
589
- throw err;
590
- }
591
- finally {
592
- (0, serverless_1.forgetBrowserEventLoop)(params.logLevel);
593
- }
594
- };
595
- exports.launchHandler = launchHandler;
@@ -1,11 +0,0 @@
1
- import type { CloudProvider, ProviderSpecifics } from '@remotion/serverless';
2
- import type { ServerlessPayload } from '@remotion/serverless/client';
3
- import type { GenericRenderProgress } from '../shared/constants';
4
- type Options<Provider extends CloudProvider> = {
5
- expectedBucketOwner: string;
6
- timeoutInMilliseconds: number;
7
- retriesRemaining: number;
8
- providerSpecifics: ProviderSpecifics<Provider>;
9
- };
10
- export declare const progressHandler: <Provider extends CloudProvider>(lambdaParams: ServerlessPayload<Provider>, options: Options<Provider>) => Promise<GenericRenderProgress<Provider>>;
11
- export {};
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.progressHandler = void 0;
4
- const client_1 = require("@remotion/serverless/client");
5
- const version_1 = require("remotion/version");
6
- const get_progress_1 = require("./helpers/get-progress");
7
- const progressHandler = async (lambdaParams, options) => {
8
- var _a;
9
- if (lambdaParams.type !== client_1.ServerlessRoutines.status) {
10
- throw new TypeError('Expected status type');
11
- }
12
- if (lambdaParams.version !== version_1.VERSION) {
13
- if (!lambdaParams.version) {
14
- throw new Error(`Version mismatch: When calling getRenderProgress(), you called the function ${process.env.AWS_LAMBDA_FUNCTION_NAME} which has the version ${version_1.VERSION} but the @remotion/lambda package is an older version. Deploy a new function and use it to call getRenderProgress(). See: https://www.remotion.dev/docs/lambda/upgrading`);
15
- }
16
- throw new Error(`Version mismatch: When calling getRenderProgress(), you passed ${process.env.AWS_LAMBDA_FUNCTION_NAME} as the function, which has the version ${version_1.VERSION}, but the @remotion/lambda package you used to invoke the function has version ${lambdaParams.version}. Deploy a new function and use it to call getRenderProgress(). See: https://www.remotion.dev/docs/lambda/upgrading`);
17
- }
18
- try {
19
- const progress = await (0, get_progress_1.getProgress)({
20
- bucketName: lambdaParams.bucketName,
21
- renderId: lambdaParams.renderId,
22
- expectedBucketOwner: options.expectedBucketOwner,
23
- region: options.providerSpecifics.getCurrentRegionInFunction(),
24
- memorySizeInMb: Number(process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE),
25
- timeoutInMilliseconds: options.timeoutInMilliseconds,
26
- customCredentials: (_a = lambdaParams.s3OutputProvider) !== null && _a !== void 0 ? _a : null,
27
- providerSpecifics: options.providerSpecifics,
28
- forcePathStyle: lambdaParams.forcePathStyle,
29
- functionName: process.env.AWS_LAMBDA_FUNCTION_NAME,
30
- });
31
- return progress;
32
- }
33
- catch (err) {
34
- if (options.retriesRemaining === 0) {
35
- throw err;
36
- }
37
- if (err.message.includes('No render with ID')) {
38
- await new Promise((resolve) => {
39
- setTimeout(resolve, 1000);
40
- });
41
- return (0, exports.progressHandler)(lambdaParams, {
42
- expectedBucketOwner: options.expectedBucketOwner,
43
- timeoutInMilliseconds: options.timeoutInMilliseconds,
44
- retriesRemaining: options.retriesRemaining - 1,
45
- providerSpecifics: options.providerSpecifics,
46
- });
47
- }
48
- throw err;
49
- }
50
- };
51
- exports.progressHandler = progressHandler;
@@ -1,17 +0,0 @@
1
- import type { CloudProvider, OnStream, ProviderSpecifics } from '@remotion/serverless';
2
- import type { ServerlessPayload } from '@remotion/serverless/client';
3
- import type { RequestContext } from './helpers/request-context';
4
- type Options = {
5
- expectedBucketOwner: string;
6
- isWarm: boolean;
7
- };
8
- export declare const rendererHandler: <Provider extends CloudProvider>({ onStream, options, params, providerSpecifics, requestContext, }: {
9
- params: ServerlessPayload<Provider>;
10
- options: Options;
11
- onStream: OnStream<Provider>;
12
- requestContext: RequestContext;
13
- providerSpecifics: ProviderSpecifics<Provider>;
14
- }) => Promise<{
15
- type: "success";
16
- }>;
17
- export {};