@remotion/lambda 3.3.94 → 3.3.96

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.
@@ -0,0 +1,16 @@
1
+ /// <reference types="node" />
2
+ import { Stream } from 'stream';
3
+ export declare class ResponseStream extends Stream.Writable {
4
+ private response;
5
+ _contentType?: string;
6
+ _isBase64Encoded?: boolean;
7
+ constructor();
8
+ _write(chunk: string, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
9
+ getBufferedData(): Buffer;
10
+ setContentType(contentType: string): void;
11
+ setIsBase64Encoded(isBase64Encoded: boolean): void;
12
+ }
13
+ export declare const HANDLER_STREAMING: unique symbol;
14
+ export declare const STREAM_RESPONSE = "response";
15
+ export declare function isInAWS(handler: Function): boolean;
16
+ export declare function streamifyResponse(handler: Function): Function;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.streamifyResponse = exports.isInAWS = exports.STREAM_RESPONSE = exports.HANDLER_STREAMING = exports.ResponseStream = void 0;
4
+ const stream_1 = require("stream");
5
+ class ResponseStream extends stream_1.Stream.Writable {
6
+ constructor() {
7
+ super();
8
+ this.response = [];
9
+ }
10
+ _write(chunk, encoding, callback) {
11
+ this.response.push(Buffer.from(chunk, encoding));
12
+ callback();
13
+ }
14
+ getBufferedData() {
15
+ return Buffer.concat(this.response);
16
+ }
17
+ setContentType(contentType) {
18
+ this._contentType = contentType;
19
+ }
20
+ setIsBase64Encoded(isBase64Encoded) {
21
+ this._isBase64Encoded = isBase64Encoded;
22
+ }
23
+ }
24
+ exports.ResponseStream = ResponseStream;
25
+ exports.HANDLER_STREAMING = Symbol.for('aws.lambda.runtime.handler.streaming');
26
+ exports.STREAM_RESPONSE = 'response';
27
+ function isInAWS(handler) {
28
+ return (
29
+ // @ts-expect-error
30
+ handler[exports.HANDLER_STREAMING] !== undefined &&
31
+ // @ts-expect-error
32
+ handler[exports.HANDLER_STREAMING] === exports.STREAM_RESPONSE);
33
+ }
34
+ exports.isInAWS = isInAWS;
35
+ function streamifyResponse(handler) {
36
+ // Check for global awslambda
37
+ if (isInAWS(handler)) {
38
+ // @ts-expect-error
39
+ return awslambda.streamifyResponse(handler);
40
+ }
41
+ return new Proxy(handler, {
42
+ async apply(target, _, argList) {
43
+ const responseStream = patchArgs(argList);
44
+ await target(...argList);
45
+ return {
46
+ statusCode: 200,
47
+ headers: {
48
+ 'content-type': responseStream._contentType || 'application/json',
49
+ },
50
+ ...(responseStream._isBase64Encoded
51
+ ? { isBase64Encoded: responseStream._isBase64Encoded }
52
+ : {}),
53
+ body: responseStream._isBase64Encoded
54
+ ? responseStream.getBufferedData().toString('base64')
55
+ : responseStream.getBufferedData().toString(),
56
+ };
57
+ },
58
+ });
59
+ }
60
+ exports.streamifyResponse = streamifyResponse;
61
+ function patchArgs(argList) {
62
+ if (!(argList[1] instanceof ResponseStream)) {
63
+ const responseStream = new ResponseStream();
64
+ argList.splice(1, 0, responseStream);
65
+ }
66
+ return argList[1];
67
+ }
@@ -1,7 +1 @@
1
- import type { LambdaPayload } from '../shared/constants';
2
- import { LambdaRoutines } from '../shared/constants';
3
- import type { LambdaReturnValues } from '../shared/return-values';
4
- export declare const handler: <T extends LambdaRoutines>(params: LambdaPayload, context: {
5
- invokedFunctionArn: string;
6
- getRemainingTimeInMillis: () => number;
7
- }) => Promise<LambdaReturnValues[T]>;
1
+ export declare const handler: Function;
@@ -7,13 +7,14 @@ const compositions_1 = require("./compositions");
7
7
  const clean_tmpdir_1 = require("./helpers/clean-tmpdir");
8
8
  const is_warm_1 = require("./helpers/is-warm");
9
9
  const print_cloudwatch_helper_1 = require("./helpers/print-cloudwatch-helper");
10
+ const streamify_response_1 = require("./helpers/streamify-response");
10
11
  const info_1 = require("./info");
11
12
  const launch_1 = require("./launch");
12
13
  const progress_1 = require("./progress");
13
14
  const renderer_2 = require("./renderer");
14
15
  const start_1 = require("./start");
15
16
  const still_1 = require("./still");
16
- const handler = async (params, context) => {
17
+ exports.handler = (0, streamify_response_1.streamifyResponse)(async (params, responseStream, context) => {
17
18
  process.env.__RESERVED_IS_INSIDE_REMOTION_LAMBDA = 'true';
18
19
  const timeoutInMilliseconds = context.getRemainingTimeInMillis();
19
20
  if (!context || !context.invokedFunctionArn) {
@@ -28,16 +29,24 @@ const handler = async (params, context) => {
28
29
  inputProps: JSON.stringify(params.inputProps),
29
30
  isWarm,
30
31
  });
31
- return (0, still_1.stillHandler)(params, {
32
+ const response = await (0, still_1.stillHandler)(params, {
32
33
  expectedBucketOwner: currentUserId,
33
34
  });
35
+ responseStream.write(JSON.stringify(response));
36
+ responseStream.end();
37
+ return;
34
38
  }
35
39
  if (params.type === constants_1.LambdaRoutines.start) {
36
40
  (0, print_cloudwatch_helper_1.printCloudwatchHelper)(constants_1.LambdaRoutines.start, {
37
41
  inputProps: JSON.stringify(params.inputProps),
38
42
  isWarm,
39
43
  });
40
- return (0, start_1.startHandler)(params, { expectedBucketOwner: currentUserId });
44
+ const response = await (0, start_1.startHandler)(params, {
45
+ expectedBucketOwner: currentUserId,
46
+ });
47
+ responseStream.write(JSON.stringify(response));
48
+ responseStream.end();
49
+ return;
41
50
  }
42
51
  if (params.type === constants_1.LambdaRoutines.launch) {
43
52
  (0, print_cloudwatch_helper_1.printCloudwatchHelper)(constants_1.LambdaRoutines.launch, {
@@ -45,20 +54,25 @@ const handler = async (params, context) => {
45
54
  inputProps: JSON.stringify(params.inputProps),
46
55
  isWarm,
47
56
  });
48
- return (0, launch_1.launchHandler)(params, {
57
+ await (0, launch_1.launchHandler)(params, {
49
58
  expectedBucketOwner: currentUserId,
50
59
  getRemainingTimeInMillis: context.getRemainingTimeInMillis,
51
60
  });
61
+ responseStream.end();
62
+ return;
52
63
  }
53
64
  if (params.type === constants_1.LambdaRoutines.status) {
54
65
  (0, print_cloudwatch_helper_1.printCloudwatchHelper)(constants_1.LambdaRoutines.status, {
55
66
  renderId: params.renderId,
56
67
  isWarm,
57
68
  });
58
- return (0, progress_1.progressHandler)(params, {
69
+ const response = await (0, progress_1.progressHandler)(params, {
59
70
  expectedBucketOwner: currentUserId,
60
71
  timeoutInMilliseconds,
61
72
  });
73
+ responseStream.write(JSON.stringify(response));
74
+ responseStream.end();
75
+ return;
62
76
  }
63
77
  if (params.type === constants_1.LambdaRoutines.renderer) {
64
78
  (0, print_cloudwatch_helper_1.printCloudwatchHelper)(constants_1.LambdaRoutines.renderer, {
@@ -68,25 +82,32 @@ const handler = async (params, context) => {
68
82
  inputProps: JSON.stringify(params.inputProps),
69
83
  isWarm,
70
84
  });
71
- return (0, renderer_2.rendererHandler)(params, {
85
+ await (0, renderer_2.rendererHandler)(params, {
72
86
  expectedBucketOwner: currentUserId,
73
87
  isWarm,
74
88
  });
89
+ responseStream.end();
90
+ return;
75
91
  }
76
92
  if (params.type === constants_1.LambdaRoutines.info) {
77
93
  (0, print_cloudwatch_helper_1.printCloudwatchHelper)(constants_1.LambdaRoutines.info, {
78
94
  isWarm,
79
95
  });
80
- return (0, info_1.infoHandler)(params);
96
+ const response = await (0, info_1.infoHandler)(params);
97
+ responseStream.write(JSON.stringify(response));
98
+ responseStream.end();
99
+ return;
81
100
  }
82
101
  if (params.type === constants_1.LambdaRoutines.compositions) {
83
102
  (0, print_cloudwatch_helper_1.printCloudwatchHelper)(constants_1.LambdaRoutines.compositions, {
84
103
  isWarm,
85
104
  });
86
- return (0, compositions_1.compositionsHandler)(params, {
105
+ const response = await (0, compositions_1.compositionsHandler)(params, {
87
106
  expectedBucketOwner: currentUserId,
88
107
  });
108
+ responseStream.write(JSON.stringify(response));
109
+ responseStream.end();
110
+ return;
89
111
  }
90
112
  throw new Error(constants_1.COMMAND_NOT_FOUND);
91
- };
92
- exports.handler = handler;
113
+ });
@@ -5,30 +5,44 @@ const client_lambda_1 = require("@aws-sdk/client-lambda");
5
5
  const aws_clients_1 = require("./aws-clients");
6
6
  const callLambda = async ({ functionName, type, payload, region, }) => {
7
7
  var _a;
8
- const res = await (0, aws_clients_1.getLambdaClient)(region).send(new client_lambda_1.InvokeCommand({
8
+ const res = await (0, aws_clients_1.getLambdaClient)(region).send(new client_lambda_1.InvokeWithResponseStreamCommand({
9
9
  FunctionName: functionName,
10
10
  // @ts-expect-error
11
11
  Payload: JSON.stringify({ type, ...payload }),
12
12
  }));
13
- const string = Buffer.from(res.Payload).toString();
14
- const json = JSON.parse(string);
15
- if (json === null) {
16
- throw new Error('Lambda function unexpectedly returned null: ' +
17
- JSON.stringify({
18
- payload,
19
- type,
20
- functionName,
21
- json,
22
- error: res.FunctionError,
23
- version: res.$metadata,
24
- }));
13
+ const events = res.EventStream;
14
+ let responsePayload = new Uint8Array();
15
+ for await (const event of events) {
16
+ // There are two types of events you can get on a stream.
17
+ // `PayloadChunk`: These contain the actual raw bytes of the chunk
18
+ // It has a single property: `Payload`
19
+ if (event.PayloadChunk) {
20
+ // Decode the raw bytes into a string a human can read
21
+ const decoded = new TextDecoder('utf-8').decode(event.PayloadChunk.Payload);
22
+ responsePayload = Buffer.concat([responsePayload, Buffer.from(decoded)]);
23
+ }
24
+ if (event.InvokeComplete) {
25
+ if (event.InvokeComplete.ErrorCode) {
26
+ throw new Error(`Lambda function ${functionName} failed with error code ${event.InvokeComplete.ErrorCode}: ${event.InvokeComplete.ErrorDetails}}`);
27
+ }
28
+ }
25
29
  }
30
+ const string = Buffer.from(responsePayload).toString();
31
+ const json = JSON.parse(string);
26
32
  if ('errorMessage' in json) {
27
33
  const err = new Error(json.errorMessage);
28
34
  err.name = json.errorType;
29
35
  err.stack = ((_a = json.trace) !== null && _a !== void 0 ? _a : []).join('\n');
30
36
  throw err;
31
37
  }
38
+ // Streaming: 3.3.96+
39
+ if ('statusCode' in json) {
40
+ if (json.statusCode !== 200) {
41
+ throw new Error(`Lambda function ${functionName} failed with status code ${json.statusCode}: ${json.body}`);
42
+ }
43
+ return JSON.parse(json.body);
44
+ }
45
+ // Non-streaming: 3.3.95 and below
32
46
  return json;
33
47
  };
34
48
  exports.callLambda = callLambda;
@@ -15,3 +15,8 @@ export interface LambdaReturnValues {
15
15
  [LambdaRoutines.still]: ReturnType<typeof stillHandler>;
16
16
  [LambdaRoutines.compositions]: ReturnType<typeof compositionsHandler>;
17
17
  }
18
+ export declare type StreamedResponse = {
19
+ statusCode: number;
20
+ headers: Record<string, string>;
21
+ body: string;
22
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remotion/lambda",
3
- "version": "3.3.94",
3
+ "version": "3.3.96",
4
4
  "description": "Distributed renderer for Remotion based on AWS Lambda",
5
5
  "main": "dist/index.js",
6
6
  "sideEffects": false,
@@ -13,28 +13,28 @@
13
13
  "url": "https://github.com/JonnyBurger/remotion"
14
14
  },
15
15
  "dependencies": {
16
- "@aws-sdk/abort-controller": "3.272.0",
17
- "@aws-sdk/client-cloudwatch-logs": "3.272.0",
18
- "@aws-sdk/client-iam": "3.272.0",
19
- "@aws-sdk/client-lambda": "3.272.0",
20
- "@aws-sdk/client-s3": "3.272.0",
21
- "@aws-sdk/client-service-quotas": "3.272.0",
22
- "@aws-sdk/client-sts": "3.272.0",
23
- "@aws-sdk/credential-providers": "3.272.0",
24
- "@aws-sdk/lib-storage": "3.272.0",
25
- "@aws-sdk/s3-request-presigner": "3.272.0",
26
- "@remotion/bundler": "3.3.94",
27
- "@remotion/cli": "3.3.94",
28
- "@remotion/renderer": "3.3.94",
16
+ "@aws-sdk/abort-controller": "3.338.0",
17
+ "@aws-sdk/client-cloudwatch-logs": "3.338.0",
18
+ "@aws-sdk/client-iam": "3.338.0",
19
+ "@aws-sdk/client-lambda": "3.338.0",
20
+ "@aws-sdk/client-s3": "3.338.0",
21
+ "@aws-sdk/client-service-quotas": "3.338.0",
22
+ "@aws-sdk/client-sts": "3.338.0",
23
+ "@aws-sdk/credential-providers": "3.338.0",
24
+ "@aws-sdk/lib-storage": "3.338.0",
25
+ "@aws-sdk/s3-request-presigner": "3.338.0",
26
+ "@remotion/bundler": "3.3.96",
27
+ "@remotion/cli": "3.3.96",
28
+ "@remotion/renderer": "3.3.96",
29
29
  "aws-policies": "^1.0.1",
30
30
  "mime-types": "2.1.34",
31
- "remotion": "3.3.94"
31
+ "remotion": "3.3.96"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@jonny/eslint-config": "3.0.266",
35
- "@remotion/bundler": "3.3.94",
36
- "@remotion/compositor-linux-arm64-musl": "3.3.94",
37
- "@remotion/compositor-linux-x64-musl": "3.3.94",
35
+ "@remotion/bundler": "3.3.96",
36
+ "@remotion/compositor-linux-arm64-musl": "3.3.96",
37
+ "@remotion/compositor-linux-x64-musl": "3.3.96",
38
38
  "@types/mime-types": "2.1.1",
39
39
  "@types/minimist": "1.2.2",
40
40
  "@types/node": "^14.14.14",
@@ -48,7 +48,7 @@
48
48
  "zip-lib": "^0.7.2"
49
49
  },
50
50
  "peerDependencies": {
51
- "@remotion/bundler": "3.3.94"
51
+ "@remotion/bundler": "3.3.96"
52
52
  },
53
53
  "publishConfig": {
54
54
  "access": "public"
Binary file
Binary file