@remotion/lambda 4.0.244 → 4.0.245

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 (70) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/admin/make-layer-public.js +10 -11
  3. package/dist/api/create-function.d.ts +1 -2
  4. package/dist/api/create-function.js +10 -10
  5. package/dist/api/delete-function.d.ts +0 -7
  6. package/dist/api/delete-function.js +2 -5
  7. package/dist/api/delete-render.d.ts +0 -8
  8. package/dist/api/delete-render.js +2 -6
  9. package/dist/api/delete-site.d.ts +0 -10
  10. package/dist/api/delete-site.js +3 -9
  11. package/dist/api/deploy-function.d.ts +3 -14
  12. package/dist/api/deploy-function.js +5 -13
  13. package/dist/api/deploy-site.d.ts +0 -9
  14. package/dist/api/deploy-site.js +3 -8
  15. package/dist/api/download-media.d.ts +0 -11
  16. package/dist/api/download-media.js +1 -8
  17. package/dist/api/estimate-price.d.ts +0 -6
  18. package/dist/api/estimate-price.js +1 -3
  19. package/dist/api/get-aws-client.d.ts +0 -8
  20. package/dist/api/get-aws-client.js +2 -6
  21. package/dist/api/get-compositions-on-lambda.d.ts +0 -13
  22. package/dist/api/get-compositions-on-lambda.js +2 -11
  23. package/dist/api/get-function-info.d.ts +0 -7
  24. package/dist/api/get-function-info.js +2 -5
  25. package/dist/api/get-functions.d.ts +0 -7
  26. package/dist/api/get-functions.js +2 -5
  27. package/dist/api/get-or-create-bucket.d.ts +0 -6
  28. package/dist/api/get-or-create-bucket.js +3 -5
  29. package/dist/api/get-regions.d.ts +0 -5
  30. package/dist/api/get-regions.js +3 -4
  31. package/dist/api/get-render-progress.d.ts +0 -10
  32. package/dist/api/get-render-progress.js +1 -7
  33. package/dist/api/get-sites.d.ts +0 -6
  34. package/dist/api/get-sites.js +3 -5
  35. package/dist/api/iam-validation/simulate.d.ts +0 -7
  36. package/dist/api/iam-validation/simulate.js +2 -5
  37. package/dist/api/iam-validation/suggested-policy.d.ts +0 -10
  38. package/dist/api/iam-validation/suggested-policy.js +2 -4
  39. package/dist/api/presign-url.d.ts +0 -10
  40. package/dist/api/presign-url.js +2 -8
  41. package/dist/api/render-media-on-lambda.d.ts +0 -19
  42. package/dist/api/render-media-on-lambda.js +2 -17
  43. package/dist/api/render-still-on-lambda.d.ts +0 -16
  44. package/dist/api/render-still-on-lambda.js +3 -15
  45. package/dist/api/speculate-function-name.d.ts +0 -8
  46. package/dist/api/speculate-function-name.js +3 -7
  47. package/dist/api/validate-webhook-signature.d.ts +0 -8
  48. package/dist/api/validate-webhook-signature.js +3 -7
  49. package/dist/cli/commands/functions/deploy.js +4 -1
  50. package/dist/functions/http-client.d.ts +7 -0
  51. package/dist/functions/http-client.js +22 -0
  52. package/dist/index.js +26 -5
  53. package/dist/pricing/price-per-1-s.js +102 -0
  54. package/dist/regions.d.ts +1 -1
  55. package/dist/regions.js +3 -0
  56. package/dist/shared/call-lambda-async.d.ts +3 -0
  57. package/dist/shared/call-lambda-async.js +20 -0
  58. package/dist/shared/call-lambda-streaming.d.ts +7 -0
  59. package/dist/shared/call-lambda-streaming.js +124 -0
  60. package/dist/shared/call-lambda-sync.d.ts +3 -0
  61. package/dist/shared/call-lambda-sync.js +30 -0
  62. package/dist/shared/get-layers.d.ts +1 -2
  63. package/dist/shared/get-layers.js +2 -4
  64. package/dist/shared/hosted-layers.d.ts +0 -1
  65. package/dist/shared/hosted-layers.js +139 -537
  66. package/dist/shared/lambda-insights-extensions.d.ts +1 -1
  67. package/dist/shared/lambda-insights-extensions.js +3 -0
  68. package/dist/shared/validate-aws-region.js +1 -1
  69. package/package.json +12 -12
  70. package/remotionlambda-arm64.zip +0 -0
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.callFunctionWithStreamingImplementation = exports.parseJsonOrThrowSource = void 0;
4
+ const client_lambda_1 = require("@aws-sdk/client-lambda");
5
+ const client_1 = require("@remotion/serverless/client");
6
+ const streaming_1 = require("@remotion/streaming");
7
+ const aws_clients_1 = require("./aws-clients");
8
+ const STREAM_STALL_TIMEOUT = 30000;
9
+ const LAMBDA_STREAM_STALL = `AWS did not invoke Lambda in ${STREAM_STALL_TIMEOUT}ms`;
10
+ const parseJsonOrThrowSource = (data, type) => {
11
+ const asString = new TextDecoder('utf-8').decode(data);
12
+ try {
13
+ return JSON.parse(asString);
14
+ }
15
+ catch (_a) {
16
+ throw new Error(`Invalid JSON (${type}): ${asString}`);
17
+ }
18
+ };
19
+ exports.parseJsonOrThrowSource = parseJsonOrThrowSource;
20
+ const invokeStreamOrTimeout = async ({ region, timeoutInTest, functionName, type, payload, }) => {
21
+ const resProm = (0, aws_clients_1.getLambdaClient)(region, timeoutInTest).send(new client_lambda_1.InvokeWithResponseStreamCommand({
22
+ FunctionName: functionName,
23
+ Payload: JSON.stringify({ type, ...payload }),
24
+ }));
25
+ let cleanup = () => undefined;
26
+ const timeout = new Promise((_resolve, reject) => {
27
+ const int = setTimeout(() => {
28
+ reject(new Error(LAMBDA_STREAM_STALL));
29
+ }, STREAM_STALL_TIMEOUT);
30
+ cleanup = () => {
31
+ clearTimeout(int);
32
+ };
33
+ });
34
+ const res = await Promise.race([resProm, timeout]);
35
+ cleanup();
36
+ return res;
37
+ };
38
+ const INVALID_JSON_MESSAGE = 'Cannot parse Lambda response as JSON';
39
+ const callLambdaWithStreamingWithoutRetry = async ({ functionName, type, payload, region, timeoutInTest, receivedStreamingPayload, }) => {
40
+ const res = await invokeStreamOrTimeout({
41
+ functionName,
42
+ payload,
43
+ region,
44
+ timeoutInTest,
45
+ type,
46
+ });
47
+ const { onData, clear } = (0, streaming_1.makeStreamer)((status, messageTypeId, data) => {
48
+ const messageType = (0, client_1.messageTypeIdToMessageType)(messageTypeId);
49
+ const innerPayload = client_1.formatMap[messageType] === 'json'
50
+ ? (0, exports.parseJsonOrThrowSource)(data, messageType)
51
+ : data;
52
+ const message = {
53
+ successType: status,
54
+ message: {
55
+ type: messageType,
56
+ payload: innerPayload,
57
+ },
58
+ };
59
+ receivedStreamingPayload(message);
60
+ });
61
+ const dumpBuffers = () => {
62
+ clear();
63
+ };
64
+ // @ts-expect-error - We are adding a listener to a global variable
65
+ if (globalThis._dumpUnreleasedBuffers) {
66
+ // @ts-expect-error - We are adding a listener to a global variable
67
+ globalThis._dumpUnreleasedBuffers.addListener('dump-unreleased-buffers', dumpBuffers);
68
+ }
69
+ const events = res.EventStream;
70
+ for await (const event of events) {
71
+ // There are two types of events you can get on a stream.
72
+ // `PayloadChunk`: These contain the actual raw bytes of the chunk
73
+ // It has a single property: `Payload`
74
+ if (event.PayloadChunk && event.PayloadChunk.Payload) {
75
+ onData(event.PayloadChunk.Payload);
76
+ }
77
+ if (event.InvokeComplete) {
78
+ if (event.InvokeComplete.ErrorCode) {
79
+ const logs = `https://${region}.console.aws.amazon.com/cloudwatch/home?region=${region}#logsV2:logs-insights$3FqueryDetail$3D~(end~0~start~-3600~timeType~'RELATIVE~unit~'seconds~editorString~'fields*20*40timestamp*2c*20*40requestId*2c*20*40message*0a*7c*20filter*20*40requestId*20like*20*${res.$metadata.requestId}*22*0a*7c*20sort*20*40timestamp*20asc~source~(~'*2faws*2flambda*2f${functionName}))`;
80
+ if (event.InvokeComplete.ErrorCode === 'Unhandled') {
81
+ throw new Error(`Lambda function ${functionName} failed with an unhandled error: ${event.InvokeComplete.ErrorDetails} See ${logs} to see the logs of this invocation.`);
82
+ }
83
+ throw new Error(`Lambda function ${functionName} failed with error code ${event.InvokeComplete.ErrorCode}: ${event.InvokeComplete.ErrorDetails}. See ${logs} to see the logs of this invocation.`);
84
+ }
85
+ }
86
+ // Don't put a `break` statement here, as it will cause the socket to not properly exit.
87
+ }
88
+ // @ts-expect-error - We are adding a listener to a global variable
89
+ if (globalThis._dumpUnreleasedBuffers) {
90
+ // @ts-expect-error - We are adding a listener to a global variable
91
+ globalThis._dumpUnreleasedBuffers.removeListener('dump-unreleased-buffers', dumpBuffers);
92
+ }
93
+ clear();
94
+ };
95
+ const callFunctionWithStreamingImplementation = async (options) => {
96
+ // As of August 2023, Lambda streaming sometimes misses parts of the JSON response.
97
+ // Handling this for now by applying a retry mechanism.
98
+ var _a;
99
+ try {
100
+ // Do not remove this await
101
+ await callLambdaWithStreamingWithoutRetry(options);
102
+ }
103
+ catch (err) {
104
+ if ((_a = err.stack) === null || _a === void 0 ? void 0 : _a.includes('TooManyRequestsException')) {
105
+ throw new Error(`AWS Concurrency limit reached (Original Error: ${err.message}). See https://www.remotion.dev/docs/lambda/troubleshooting/rate-limit for tips to fix this.`);
106
+ }
107
+ if (!err.message.includes(INVALID_JSON_MESSAGE) &&
108
+ !err.message.includes(LAMBDA_STREAM_STALL) &&
109
+ !err.message.includes('aborted')) {
110
+ throw err;
111
+ }
112
+ console.error('Retries remaining:', options.retriesRemaining);
113
+ if (options.retriesRemaining === 0) {
114
+ console.error('Throwing error:');
115
+ throw err;
116
+ }
117
+ console.error(err);
118
+ return (0, exports.callFunctionWithStreamingImplementation)({
119
+ ...options,
120
+ retriesRemaining: options.retriesRemaining - 1,
121
+ });
122
+ }
123
+ };
124
+ exports.callFunctionWithStreamingImplementation = callFunctionWithStreamingImplementation;
@@ -0,0 +1,3 @@
1
+ import type { CallFunctionOptions, CloudProvider, ServerlessReturnValues } from '@remotion/serverless';
2
+ import type { ServerlessRoutines } from '@remotion/serverless/client';
3
+ export declare const callFunctionSyncImplementation: <Provider extends CloudProvider, T extends ServerlessRoutines>(options: CallFunctionOptions<T, Provider>) => Promise<ServerlessReturnValues<Provider>[T]>;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.callFunctionSyncImplementation = void 0;
4
+ const client_lambda_1 = require("@aws-sdk/client-lambda");
5
+ const aws_clients_1 = require("./aws-clients");
6
+ const callLambdaSyncWithoutRetry = async ({ functionName, payload, region, timeoutInTest, }) => {
7
+ const Payload = JSON.stringify(payload);
8
+ const res = await (0, aws_clients_1.getLambdaClient)(region, timeoutInTest).send(new client_lambda_1.InvokeCommand({
9
+ FunctionName: functionName,
10
+ Payload,
11
+ InvocationType: 'RequestResponse',
12
+ }));
13
+ const decoded = new TextDecoder('utf-8').decode(res.Payload);
14
+ try {
15
+ return JSON.parse(decoded);
16
+ }
17
+ catch (_a) {
18
+ throw new Error(`Invalid JSON: ${JSON.stringify(decoded)}`);
19
+ }
20
+ };
21
+ const callFunctionSyncImplementation = async (options) => {
22
+ const res = await callLambdaSyncWithoutRetry(options);
23
+ if (res.type === 'error') {
24
+ const err = new Error(res.message);
25
+ err.stack = res.stack;
26
+ throw err;
27
+ }
28
+ return res;
29
+ };
30
+ exports.callFunctionSyncImplementation = callFunctionSyncImplementation;
@@ -3,9 +3,8 @@ import type { AwsLayer } from './hosted-layers';
3
3
  declare const runtimePreferenceOptions: readonly ["default", "apple-emojis", "cjk"];
4
4
  export type RuntimePreference = (typeof runtimePreferenceOptions)[number];
5
5
  export declare const validateRuntimePreference: (option: unknown) => void;
6
- export declare const getLayers: ({ option, region, enableV5Runtime, }: {
6
+ export declare const getLayers: ({ option, region, }: {
7
7
  option: RuntimePreference;
8
8
  region: AwsRegion;
9
- enableV5Runtime: boolean;
10
9
  }) => AwsLayer[];
11
10
  export {};
@@ -12,10 +12,8 @@ const validateRuntimePreference = (option) => {
12
12
  }
13
13
  };
14
14
  exports.validateRuntimePreference = validateRuntimePreference;
15
- const getLayers = ({ option, region, enableV5Runtime, }) => {
16
- const layers = enableV5Runtime
17
- ? hosted_layers_1.v5HostedLayers[region]
18
- : hosted_layers_1.hostedLayers[region];
15
+ const getLayers = ({ option, region, }) => {
16
+ const layers = hosted_layers_1.hostedLayers[region];
19
17
  return layers.filter((layer) => {
20
18
  if (layer.layerArn.includes('emoji-apple')) {
21
19
  return option === 'apple-emojis';
@@ -8,4 +8,3 @@ export type HostedLayers = {
8
8
  [region in AwsRegion]: AwsLayer[];
9
9
  };
10
10
  export declare const hostedLayers: HostedLayers;
11
- export declare const v5HostedLayers: HostedLayers;