@remotion/lambda-client 4.0.363 → 4.0.365

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 (168) hide show
  1. package/dist/cjs/app-router-webhook.d.ts +10 -0
  2. package/dist/cjs/apply-lifecycle.d.ts +8 -0
  3. package/dist/cjs/aws-clients.d.ts +12 -0
  4. package/dist/cjs/aws-provider.d.ts +27 -0
  5. package/dist/cjs/bucket-exists.d.ts +3 -0
  6. package/dist/cjs/call-lambda-async.d.ts +2 -0
  7. package/dist/cjs/call-lambda-streaming.d.ts +6 -0
  8. package/dist/cjs/call-lambda-sync.d.ts +2 -0
  9. package/dist/cjs/check-credentials.d.ts +1 -0
  10. package/dist/cjs/clean-items.d.ts +17 -0
  11. package/dist/cjs/constants.d.ts +25 -0
  12. package/dist/cjs/constants.js +75 -0
  13. package/dist/cjs/content-disposition-header.d.ts +2 -0
  14. package/dist/cjs/convert-to-serve-url.d.ts +6 -0
  15. package/dist/cjs/create-bucket.d.ts +3 -0
  16. package/dist/cjs/delete-file.d.ts +3 -0
  17. package/dist/cjs/delete-function.d.ts +7 -0
  18. package/dist/cjs/delete-render.d.ts +22 -0
  19. package/dist/cjs/encode-aws-url-params.d.ts +1 -0
  20. package/dist/cjs/estimate-price.d.ts +17 -0
  21. package/dist/cjs/express-webhook.d.ts +3 -0
  22. package/dist/cjs/get-account-id.d.ts +3 -0
  23. package/dist/cjs/get-aws-client.d.ts +32 -0
  24. package/dist/cjs/get-aws-urls.d.ts +25 -0
  25. package/dist/cjs/get-buckets.d.ts +9 -0
  26. package/dist/cjs/get-compositions-on-lambda.d.ts +20 -0
  27. package/dist/cjs/get-credentials.d.ts +9 -0
  28. package/dist/cjs/get-env-variable.d.ts +1 -0
  29. package/dist/cjs/get-function-name.d.ts +8 -0
  30. package/dist/cjs/get-function-version.d.ts +9 -0
  31. package/dist/cjs/get-functions.d.ts +10 -0
  32. package/dist/cjs/get-output-url-from-metadata.d.ts +3 -0
  33. package/dist/cjs/get-render-progress.d.ts +17 -0
  34. package/dist/cjs/get-s3-client.d.ts +11 -0
  35. package/dist/cjs/get-service-client.d.ts +25 -0
  36. package/dist/cjs/get-sites.d.ts +31 -0
  37. package/dist/cjs/head-file.d.ts +3 -0
  38. package/dist/cjs/index.d.ts +129 -0
  39. package/dist/cjs/index.js +72692 -0
  40. package/dist/cjs/is-cli.d.ts +2 -0
  41. package/dist/cjs/is-flaky-error.d.ts +1 -0
  42. package/dist/cjs/is-in-lambda.d.ts +1 -0
  43. package/dist/cjs/is-likely-to-have-aws-profile.d.ts +1 -0
  44. package/dist/cjs/lambda-version-string.d.ts +1 -0
  45. package/dist/cjs/lifecycle-rules.d.ts +12 -0
  46. package/dist/cjs/lifecycle.d.ts +7 -0
  47. package/dist/cjs/list-objects.d.ts +3 -0
  48. package/dist/cjs/make-lambda-payload.d.ts +59 -0
  49. package/dist/cjs/make-s3-url.d.ts +6 -0
  50. package/dist/cjs/p-limit.d.ts +1 -0
  51. package/dist/cjs/pages-router-webhook.d.ts +5 -0
  52. package/dist/cjs/parse-function-name.d.ts +8 -0
  53. package/dist/cjs/presign-url.d.ts +17 -0
  54. package/dist/cjs/price-per-1s.d.ts +37 -0
  55. package/dist/cjs/random-hash.d.ts +1 -0
  56. package/dist/cjs/read-file.d.ts +11 -0
  57. package/dist/cjs/regions.d.ts +3 -0
  58. package/dist/cjs/regions.js +80 -0
  59. package/dist/cjs/render-media-on-lambda.d.ts +66 -0
  60. package/dist/cjs/render-still-on-lambda.d.ts +61 -0
  61. package/dist/cjs/runtime-preference.d.ts +2 -0
  62. package/dist/cjs/speculate-function-name.d.ts +7 -0
  63. package/dist/cjs/types.d.ts +4 -0
  64. package/dist/cjs/validate-aws-region.d.ts +2 -0
  65. package/dist/cjs/validate-bucketname.d.ts +4 -0
  66. package/dist/cjs/validate-disk-size-in-mb.d.ts +1 -0
  67. package/dist/cjs/validate-lambda-codec.d.ts +2 -0
  68. package/dist/cjs/validate-memory-size.d.ts +1 -0
  69. package/dist/cjs/validate-presign-expiration.d.ts +1 -0
  70. package/dist/cjs/validate-serveurl.d.ts +1 -0
  71. package/dist/cjs/validate-webhook-signature.d.ts +5 -0
  72. package/dist/cjs/write-file.d.ts +5 -0
  73. package/dist/esm/index.mjs +64284 -13659
  74. package/package.json +15 -16
  75. package/.turbo/turbo-formatting.log +0 -4
  76. package/.turbo/turbo-lint.log +0 -25
  77. package/.turbo/turbo-make.log +0 -3
  78. package/bundle.ts +0 -24
  79. package/dist/test/concurrency-payload.test.d.ts +0 -1
  80. package/dist/test/concurrency-payload.test.js +0 -119
  81. package/dist/test/encode-aws-url.test.d.ts +0 -1
  82. package/dist/test/encode-aws-url.test.js +0 -8
  83. package/dist/test/price-calculation.test.d.ts +0 -1
  84. package/dist/test/price-calculation.test.js +0 -62
  85. package/dist/test/pricing.test.d.ts +0 -1
  86. package/dist/test/pricing.test.js +0 -27
  87. package/dist/test/request-handler.test.d.ts +0 -1
  88. package/dist/test/request-handler.test.js +0 -36
  89. package/dist/test/validate-disk-size-in-mb.test.d.ts +0 -1
  90. package/dist/test/validate-disk-size-in-mb.test.js +0 -14
  91. package/eslint.config.mjs +0 -5
  92. package/src/app-router-webhook.ts +0 -73
  93. package/src/apply-lifecycle.ts +0 -30
  94. package/src/aws-clients.ts +0 -75
  95. package/src/aws-provider.ts +0 -139
  96. package/src/bucket-exists.ts +0 -35
  97. package/src/call-lambda-async.ts +0 -43
  98. package/src/call-lambda-streaming.ts +0 -226
  99. package/src/call-lambda-sync.ts +0 -59
  100. package/src/check-credentials.ts +0 -51
  101. package/src/clean-items.ts +0 -50
  102. package/src/constants.ts +0 -38
  103. package/src/content-disposition-header.ts +0 -64
  104. package/src/convert-to-serve-url.ts +0 -24
  105. package/src/create-bucket.ts +0 -87
  106. package/src/delete-file.ts +0 -38
  107. package/src/delete-function.ts +0 -28
  108. package/src/delete-render.ts +0 -114
  109. package/src/encode-aws-url-params.ts +0 -3
  110. package/src/estimate-price.ts +0 -95
  111. package/src/express-webhook.ts +0 -57
  112. package/src/get-account-id.ts +0 -22
  113. package/src/get-aws-client.ts +0 -63
  114. package/src/get-aws-urls.ts +0 -85
  115. package/src/get-buckets.ts +0 -84
  116. package/src/get-compositions-on-lambda.ts +0 -111
  117. package/src/get-credentials.ts +0 -81
  118. package/src/get-env-variable.ts +0 -15
  119. package/src/get-function-name.ts +0 -24
  120. package/src/get-function-version.ts +0 -49
  121. package/src/get-functions.ts +0 -114
  122. package/src/get-output-url-from-metadata.ts +0 -23
  123. package/src/get-render-progress.ts +0 -66
  124. package/src/get-s3-client.ts +0 -26
  125. package/src/get-service-client.ts +0 -195
  126. package/src/get-sites.ts +0 -136
  127. package/src/head-file.ts +0 -30
  128. package/src/index.ts +0 -152
  129. package/src/is-cli.ts +0 -7
  130. package/src/is-flaky-error.ts +0 -104
  131. package/src/is-in-lambda.ts +0 -5
  132. package/src/is-likely-to-have-aws-profile.ts +0 -55
  133. package/src/lambda-version-string.ts +0 -5
  134. package/src/lifecycle-rules.ts +0 -119
  135. package/src/lifecycle.ts +0 -44
  136. package/src/list-objects.ts +0 -87
  137. package/src/make-lambda-payload.ts +0 -328
  138. package/src/make-s3-url.ts +0 -13
  139. package/src/p-limit.ts +0 -75
  140. package/src/pages-router-webhook.ts +0 -68
  141. package/src/parse-function-name.ts +0 -24
  142. package/src/presign-url.ts +0 -121
  143. package/src/price-per-1s.ts +0 -863
  144. package/src/random-hash.ts +0 -10
  145. package/src/read-file.ts +0 -35
  146. package/src/regions.ts +0 -48
  147. package/src/render-media-on-lambda.ts +0 -227
  148. package/src/render-still-on-lambda.ts +0 -209
  149. package/src/runtime-preference.ts +0 -7
  150. package/src/speculate-function-name.ts +0 -60
  151. package/src/test/concurrency-payload.test.ts +0 -121
  152. package/src/test/encode-aws-url.test.ts +0 -7
  153. package/src/test/price-calculation.test.ts +0 -62
  154. package/src/test/pricing.test.ts +0 -32
  155. package/src/test/request-handler.test.ts +0 -42
  156. package/src/test/validate-disk-size-in-mb.test.ts +0 -15
  157. package/src/types.ts +0 -7
  158. package/src/validate-aws-region.ts +0 -14
  159. package/src/validate-bucketname.ts +0 -24
  160. package/src/validate-disk-size-in-mb.ts +0 -37
  161. package/src/validate-lambda-codec.ts +0 -28
  162. package/src/validate-memory-size.ts +0 -31
  163. package/src/validate-presign-expiration.ts +0 -46
  164. package/src/validate-serveurl.ts +0 -9
  165. package/src/validate-webhook-signature.ts +0 -42
  166. package/src/write-file.ts +0 -108
  167. package/tsconfig.json +0 -9
  168. package/tsconfig.tsbuildinfo +0 -1
@@ -1,139 +0,0 @@
1
- import type {AwsRegion} from './regions';
2
-
3
- export type AwsProvider = {
4
- type: 'aws';
5
- region: AwsRegion;
6
- receivedArtifactType: {
7
- s3Key: string;
8
- s3Url: string;
9
- };
10
- creationFunctionOptions: {
11
- createCloudWatchLogGroup: boolean;
12
- accountId: string;
13
- alreadyCreated: boolean;
14
- retentionInDays: number;
15
- customRoleArn: string;
16
- enableLambdaInsights: boolean;
17
- vpcSubnetIds: string;
18
- vpcSecurityGroupIds: string;
19
- runtimePreference: RuntimePreference;
20
- };
21
- storageClass: StorageClass;
22
- requestHandler: RequestHandler | null | undefined;
23
- };
24
-
25
- import type {StorageClass} from '@aws-sdk/client-s3';
26
- import type {ProviderSpecifics} from '@remotion/serverless-client';
27
- import {expiryDays} from '@remotion/serverless-client';
28
- import {EventEmitter} from 'node:events';
29
- import {bucketExistsInRegionImplementation} from './bucket-exists';
30
- import {callFunctionAsyncImplementation} from './call-lambda-async';
31
- import {callFunctionWithStreamingImplementation} from './call-lambda-streaming';
32
- import {callFunctionSyncImplementation} from './call-lambda-sync';
33
- import {checkCredentials} from './check-credentials';
34
- import {MAX_EPHEMERAL_STORAGE_IN_MB, REMOTION_BUCKET_PREFIX} from './constants';
35
- import {convertToServeUrlImplementation} from './convert-to-serve-url';
36
- import {createBucket} from './create-bucket';
37
- import {lambdaDeleteFileImplementation} from './delete-file';
38
- import {deleteFunction} from './delete-function';
39
- import {estimatePrice} from './estimate-price';
40
- import {getAccountIdImplementation} from './get-account-id';
41
- import {getCloudwatchMethodUrl, getCloudwatchRendererUrl} from './get-aws-urls';
42
- import {getRemotionBuckets} from './get-buckets';
43
- import {getFunctions} from './get-functions';
44
- import {getOutputUrlFromMetadata} from './get-output-url-from-metadata';
45
- import {lambdaHeadFileImplementation} from './head-file';
46
- import {isFlakyError} from './is-flaky-error';
47
- import {applyLifeCyleOperation} from './lifecycle-rules';
48
- import {lambdaLsImplementation} from './list-objects';
49
- import {parseFunctionName} from './parse-function-name';
50
- import {randomHashImplementation} from './random-hash';
51
- import {lambdaReadFileImplementation} from './read-file';
52
- import type {RuntimePreference} from './runtime-preference';
53
- import type {RequestHandler} from './types';
54
- import {lambdaWriteFileImplementation} from './write-file';
55
-
56
- if (
57
- /^AWS_Lambda_nodejs(?:18|20)[.]x$/.test(
58
- process.env.AWS_EXECUTION_ENV ?? '',
59
- ) === true
60
- ) {
61
- process.env.FONTCONFIG_PATH = '/opt';
62
- process.env.FONTCONFIG_FILE = '/opt/fonts.conf';
63
-
64
- process.env.DISABLE_FROM_SURFACE = '1';
65
- process.env.NO_COLOR = '1';
66
-
67
- // @ts-expect-error
68
- globalThis._dumpUnreleasedBuffers = new EventEmitter();
69
-
70
- // @ts-expect-error
71
- (globalThis._dumpUnreleasedBuffers as EventEmitter).setMaxListeners(201);
72
- }
73
-
74
- const validateDeleteAfter = (lifeCycleValue: unknown) => {
75
- if (lifeCycleValue === null) {
76
- return;
77
- }
78
-
79
- if (lifeCycleValue === undefined) {
80
- return;
81
- }
82
-
83
- if (typeof lifeCycleValue !== 'string') {
84
- throw new TypeError(
85
- `Expected life cycle value to be a string, got ${JSON.stringify(
86
- lifeCycleValue,
87
- )}`,
88
- );
89
- }
90
-
91
- if (!(lifeCycleValue in expiryDays)) {
92
- throw new TypeError(
93
- `Expected deleteAfter value to be one of ${Object.keys(expiryDays).join(
94
- ', ',
95
- )}, got ${lifeCycleValue}`,
96
- );
97
- }
98
- };
99
-
100
- export const awsImplementation: ProviderSpecifics<AwsProvider> = {
101
- getChromiumPath() {
102
- return '/opt/bin/chromium';
103
- },
104
- getBuckets: getRemotionBuckets,
105
- createBucket,
106
- applyLifeCycle: applyLifeCyleOperation,
107
- listObjects: lambdaLsImplementation,
108
- deleteFile: lambdaDeleteFileImplementation,
109
- bucketExists: bucketExistsInRegionImplementation,
110
- randomHash: randomHashImplementation,
111
- readFile: lambdaReadFileImplementation,
112
- writeFile: lambdaWriteFileImplementation,
113
- headFile: lambdaHeadFileImplementation,
114
- convertToServeUrl: convertToServeUrlImplementation,
115
- printLoggingHelper: true,
116
- validateDeleteAfter,
117
- callFunctionAsync: callFunctionAsyncImplementation,
118
- callFunctionStreaming: callFunctionWithStreamingImplementation,
119
- callFunctionSync: callFunctionSyncImplementation,
120
- getEphemeralStorageForPriceCalculation() {
121
- // We cannot determine the ephemeral storage size, so we
122
- // overestimate the price, but will only have a miniscule effect (~0.2%)
123
- return MAX_EPHEMERAL_STORAGE_IN_MB;
124
- },
125
- estimatePrice,
126
- getLoggingUrlForMethod: getCloudwatchMethodUrl,
127
- getLoggingUrlForRendererFunction: getCloudwatchRendererUrl,
128
- isFlakyError,
129
- getOutputUrl: getOutputUrlFromMetadata,
130
- serverStorageProductName: () => 'S3',
131
- getMaxStillInlinePayloadSize: () => 5_000_000,
132
- getMaxNonInlinePayloadSizePerFunction: () => 200_000,
133
- getAccountId: getAccountIdImplementation,
134
- deleteFunction,
135
- getFunctions,
136
- parseFunctionName,
137
- checkCredentials,
138
- getBucketPrefix: () => REMOTION_BUCKET_PREFIX,
139
- };
@@ -1,35 +0,0 @@
1
- import {GetBucketLocationCommand} from '@aws-sdk/client-s3';
2
- import type {ProviderSpecifics} from '@remotion/serverless-client';
3
- import type {AwsProvider} from './aws-provider';
4
- import {getS3Client} from './get-s3-client';
5
-
6
- export const bucketExistsInRegionImplementation: ProviderSpecifics<AwsProvider>['bucketExists'] =
7
- async ({
8
- bucketName,
9
- region,
10
- expectedBucketOwner,
11
- forcePathStyle,
12
- requestHandler,
13
- }) => {
14
- try {
15
- const bucket = await getS3Client({
16
- region,
17
- customCredentials: null,
18
- forcePathStyle,
19
- requestHandler,
20
- }).send(
21
- new GetBucketLocationCommand({
22
- Bucket: bucketName,
23
- ExpectedBucketOwner: expectedBucketOwner ?? undefined,
24
- }),
25
- );
26
-
27
- return (bucket.LocationConstraint ?? 'us-east-1') === region;
28
- } catch (err) {
29
- if ((err as {Code: string}).Code === 'NoSuchBucket') {
30
- return false;
31
- }
32
-
33
- throw err;
34
- }
35
- };
@@ -1,43 +0,0 @@
1
- import {InvokeCommand} from '@aws-sdk/client-lambda';
2
- import type {
3
- CallFunctionOptions,
4
- CloudProvider,
5
- ServerlessRoutines,
6
- } from '@remotion/serverless-client';
7
- import {getLambdaClient} from './aws-clients';
8
- import type {AwsRegion} from './regions';
9
-
10
- export const callFunctionAsyncImplementation = async <
11
- T extends ServerlessRoutines,
12
- Provider extends CloudProvider,
13
- >({
14
- functionName,
15
- payload,
16
- region,
17
- timeoutInTest,
18
- }: CallFunctionOptions<T, Provider>): Promise<void> => {
19
- const stringifiedPayload = JSON.stringify(payload);
20
- if (stringifiedPayload.length > 256 * 1024) {
21
- throw new Error(
22
- `Payload is too big: ${stringifiedPayload.length} bytes. Maximum size is 256 KB. This should not happen, please report this to the Remotion team. Payload: ${stringifiedPayload}`,
23
- );
24
- }
25
-
26
- const result = await getLambdaClient(
27
- region as AwsRegion,
28
- timeoutInTest,
29
- null,
30
- ).send(
31
- new InvokeCommand({
32
- FunctionName: functionName,
33
- Payload: stringifiedPayload,
34
- InvocationType: 'Event',
35
- }),
36
- );
37
-
38
- if (result.FunctionError) {
39
- throw new Error(
40
- `Lambda function returned error: ${result.FunctionError} ${result.LogResult}`,
41
- );
42
- }
43
- };
@@ -1,226 +0,0 @@
1
- /* eslint-disable no-console */
2
- import type {InvokeWithResponseStreamCommandOutput} from '@aws-sdk/client-lambda';
3
- import {
4
- InvokeWithResponseStreamCommand,
5
- type InvokeWithResponseStreamResponseEvent,
6
- } from '@aws-sdk/client-lambda';
7
- import type {
8
- CallFunctionOptions,
9
- CloudProvider,
10
- MessageTypeId,
11
- OnMessage,
12
- ServerlessRoutines,
13
- StreamingMessage,
14
- } from '@remotion/serverless-client';
15
- import {
16
- formatMap,
17
- makeStreamer,
18
- messageTypeIdToMessageType,
19
- } from '@remotion/serverless-client';
20
- import {getLambdaClient} from './aws-clients';
21
- import type {AwsRegion} from './regions';
22
-
23
- const STREAM_STALL_TIMEOUT = 30000;
24
- const LAMBDA_STREAM_STALL = `AWS did not invoke Lambda in ${STREAM_STALL_TIMEOUT}ms`;
25
-
26
- export const parseJsonOrThrowSource = (data: Uint8Array, type: string) => {
27
- const asString = new TextDecoder('utf-8').decode(data);
28
- try {
29
- return JSON.parse(asString);
30
- } catch {
31
- throw new Error(`Invalid JSON (${type}): ${asString}`);
32
- }
33
- };
34
-
35
- const invokeStreamOrTimeout = async <Provider extends CloudProvider>({
36
- region,
37
- timeoutInTest,
38
- functionName,
39
- type,
40
- payload,
41
- }: {
42
- region: Provider['region'];
43
- timeoutInTest: number;
44
- functionName: string;
45
- type: string;
46
- payload: Record<string, unknown>;
47
- }) => {
48
- const resProm = getLambdaClient(
49
- region as AwsRegion,
50
- timeoutInTest,
51
- null,
52
- ).send(
53
- new InvokeWithResponseStreamCommand({
54
- FunctionName: functionName,
55
- Payload: JSON.stringify({type, ...payload}),
56
- }),
57
- );
58
-
59
- let cleanup = () => undefined;
60
-
61
- const timeout = new Promise<InvokeWithResponseStreamCommandOutput>(
62
- (_resolve, reject) => {
63
- const int = setTimeout(() => {
64
- reject(new Error(LAMBDA_STREAM_STALL));
65
- }, STREAM_STALL_TIMEOUT);
66
- cleanup = () => {
67
- clearTimeout(int);
68
- };
69
- },
70
- );
71
-
72
- const res = await Promise.race([resProm, timeout]);
73
-
74
- cleanup();
75
-
76
- return res;
77
- };
78
-
79
- const INVALID_JSON_MESSAGE = 'Cannot parse Lambda response as JSON';
80
-
81
- const callLambdaWithStreamingWithoutRetry = async <
82
- T extends ServerlessRoutines,
83
- Provider extends CloudProvider,
84
- >({
85
- functionName,
86
- type,
87
- payload,
88
- region,
89
- timeoutInTest,
90
- receivedStreamingPayload,
91
- }: CallFunctionOptions<T, Provider> & {
92
- receivedStreamingPayload: OnMessage<Provider>;
93
- }): Promise<void> => {
94
- const res = await invokeStreamOrTimeout({
95
- functionName,
96
- payload,
97
- region,
98
- timeoutInTest,
99
- type,
100
- });
101
-
102
- const {onData, clear} = makeStreamer((status, messageTypeId, data) => {
103
- const messageType = messageTypeIdToMessageType(
104
- messageTypeId as MessageTypeId,
105
- );
106
- const innerPayload =
107
- formatMap[messageType] === 'json'
108
- ? parseJsonOrThrowSource(data, messageType)
109
- : data;
110
-
111
- const message: StreamingMessage<Provider> = {
112
- successType: status,
113
- message: {
114
- type: messageType,
115
- payload: innerPayload,
116
- },
117
- };
118
-
119
- receivedStreamingPayload(message);
120
- });
121
-
122
- const dumpBuffers = () => {
123
- clear();
124
- };
125
-
126
- // @ts-expect-error - We are adding a listener to a global variable
127
- if (globalThis._dumpUnreleasedBuffers) {
128
- // @ts-expect-error - We are adding a listener to a global variable
129
- (globalThis._dumpUnreleasedBuffers as EventEmitter).addListener(
130
- 'dump-unreleased-buffers',
131
- dumpBuffers,
132
- );
133
- }
134
-
135
- const events =
136
- res.EventStream as AsyncIterable<InvokeWithResponseStreamResponseEvent>;
137
-
138
- for await (const event of events) {
139
- // There are two types of events you can get on a stream.
140
-
141
- // `PayloadChunk`: These contain the actual raw bytes of the chunk
142
- // It has a single property: `Payload`
143
- if (event.PayloadChunk && event.PayloadChunk.Payload) {
144
- onData(event.PayloadChunk.Payload);
145
- }
146
-
147
- if (event.InvokeComplete) {
148
- if (event.InvokeComplete.ErrorCode) {
149
- 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}))`;
150
- if (event.InvokeComplete.ErrorCode === 'Unhandled') {
151
- throw new Error(
152
- `Lambda function ${functionName} failed with an unhandled error: ${
153
- event.InvokeComplete.ErrorDetails as string
154
- } See ${logs} to see the logs of this invocation.`,
155
- );
156
- }
157
-
158
- throw new Error(
159
- `Lambda function ${functionName} failed with error code ${event.InvokeComplete.ErrorCode}: ${event.InvokeComplete.ErrorDetails}. See ${logs} to see the logs of this invocation.`,
160
- );
161
- }
162
- }
163
-
164
- // Don't put a `break` statement here, as it will cause the socket to not properly exit.
165
- }
166
-
167
- // @ts-expect-error - We are adding a listener to a global variable
168
- if (globalThis._dumpUnreleasedBuffers) {
169
- // @ts-expect-error - We are adding a listener to a global variable
170
- (globalThis._dumpUnreleasedBuffers as EventEmitter).removeListener(
171
- 'dump-unreleased-buffers',
172
- dumpBuffers,
173
- );
174
- }
175
-
176
- clear();
177
- };
178
-
179
- export const callFunctionWithStreamingImplementation = async <
180
- Provider extends CloudProvider,
181
- T extends ServerlessRoutines,
182
- >(
183
- options: CallFunctionOptions<T, Provider> & {
184
- receivedStreamingPayload: OnMessage<Provider>;
185
- retriesRemaining: number;
186
- },
187
- ): Promise<void> => {
188
- // As of August 2023, Lambda streaming sometimes misses parts of the JSON response.
189
- // Handling this for now by applying a retry mechanism.
190
-
191
- try {
192
- // Do not remove this await
193
- await callLambdaWithStreamingWithoutRetry<T, Provider>(options);
194
- } catch (err) {
195
- if (
196
- (err as Error).stack?.includes('TooManyRequestsException') ||
197
- (err as Error).message?.includes('ConcurrentInvocationLimitExceeded')
198
- ) {
199
- throw new Error(
200
- `AWS Concurrency limit reached (Original Error: ${(err as Error).message}). See https://www.remotion.dev/docs/lambda/troubleshooting/rate-limit for tips to fix this.`,
201
- );
202
- }
203
-
204
- if (
205
- !(err as Error).message.includes(INVALID_JSON_MESSAGE) &&
206
- !(err as Error).message.includes(LAMBDA_STREAM_STALL) &&
207
- // https://discord.com/channels/809501355504959528/1332166561242288220/1332166561242288220
208
- !(err as Error).message.includes('Runtime.TruncatedResponse') &&
209
- !(err as Error).message.includes('aborted')
210
- ) {
211
- throw err;
212
- }
213
-
214
- console.error('Retries remaining:', options.retriesRemaining);
215
- if (options.retriesRemaining === 0) {
216
- console.error('Throwing error:');
217
- throw err;
218
- }
219
-
220
- console.error(err);
221
- return callFunctionWithStreamingImplementation({
222
- ...options,
223
- retriesRemaining: options.retriesRemaining - 1,
224
- });
225
- }
226
- };
@@ -1,59 +0,0 @@
1
- import {InvokeCommand} from '@aws-sdk/client-lambda';
2
- import type {
3
- CallFunctionOptions,
4
- CloudProvider,
5
- OrError,
6
- ServerlessReturnValues,
7
- ServerlessRoutines,
8
- } from '@remotion/serverless-client';
9
- import {getLambdaClient} from './aws-clients';
10
- import type {AwsRegion} from './regions';
11
-
12
- const callLambdaSyncWithoutRetry = async <
13
- T extends ServerlessRoutines,
14
- Provider extends CloudProvider,
15
- >({
16
- functionName,
17
- payload,
18
- region,
19
- timeoutInTest,
20
- }: CallFunctionOptions<T, Provider>): Promise<
21
- OrError<ServerlessReturnValues<Provider>[T]>
22
- > => {
23
- const Payload = JSON.stringify(payload);
24
- const res = await getLambdaClient(
25
- region as AwsRegion,
26
- timeoutInTest,
27
- null,
28
- ).send(
29
- new InvokeCommand({
30
- FunctionName: functionName,
31
- Payload,
32
- InvocationType: 'RequestResponse',
33
- }),
34
- );
35
-
36
- const decoded = new TextDecoder('utf-8').decode(res.Payload);
37
-
38
- try {
39
- return JSON.parse(decoded) as OrError<ServerlessReturnValues<Provider>[T]>;
40
- } catch {
41
- throw new Error(`Invalid JSON: ${JSON.stringify(decoded)}`);
42
- }
43
- };
44
-
45
- export const callFunctionSyncImplementation = async <
46
- Provider extends CloudProvider,
47
- T extends ServerlessRoutines,
48
- >(
49
- options: CallFunctionOptions<T, Provider>,
50
- ): Promise<ServerlessReturnValues<Provider>[T]> => {
51
- const res = await callLambdaSyncWithoutRetry<T, Provider>(options);
52
- if (res.type === 'error') {
53
- const err = new Error(res.message);
54
- err.stack = res.stack;
55
- throw err;
56
- }
57
-
58
- return res;
59
- };
@@ -1,51 +0,0 @@
1
- import {DOCS_URL, truthy} from '@remotion/serverless-client';
2
- import {getEnvVariable} from './get-env-variable';
3
- import {getIsCli} from './is-cli';
4
- import {isLikelyToHaveAwsProfile} from './is-likely-to-have-aws-profile';
5
-
6
- const messageForVariable = (variable: string) => {
7
- return [
8
- `You have tried to call a Remotion Lambda function, but have not set the environment variable ${variable}.`,
9
- getIsCli()
10
- ? null
11
- : `- Environment variables from a '.env' file are not automatically read if you are calling the Node.JS APIs, in that case you need to load the file yourself or set the environment variables manually.`,
12
- `- Please refer to the Remotion Lambda docs (${DOCS_URL}/docs/lambda/setup) to see how to generate the credentials for your AWS account and then set the environment variables.`,
13
- `- For more reasons see the troubleshooting page: ${DOCS_URL}/docs/lambda/troubleshooting/permissions`,
14
- ]
15
- .filter(truthy)
16
- .join('\n');
17
- };
18
-
19
- export const checkCredentials = () => {
20
- if (getEnvVariable('REMOTION_SKIP_AWS_CREDENTIALS_CHECK')) {
21
- return;
22
- }
23
-
24
- if (getEnvVariable('REMOTION_AWS_PROFILE') || getEnvVariable('AWS_PROFILE')) {
25
- return;
26
- }
27
-
28
- if (isLikelyToHaveAwsProfile()) {
29
- return;
30
- }
31
-
32
- if (
33
- !getEnvVariable('AWS_ACCESS_KEY_ID') &&
34
- !getEnvVariable('REMOTION_AWS_ACCESS_KEY_ID')
35
- ) {
36
- throw new Error(
37
- messageForVariable('AWS_ACCESS_KEY_ID or REMOTION_AWS_ACCESS_KEY_ID'),
38
- );
39
- }
40
-
41
- if (
42
- !getEnvVariable('AWS_SECRET_ACCESS_KEY') &&
43
- !getEnvVariable('REMOTION_AWS_SECRET_ACCESS_KEY')
44
- ) {
45
- throw new Error(
46
- messageForVariable(
47
- 'AWS_SECRET_ACCESS_KEY or REMOTION_AWS_SECRET_ACCESS_KEY',
48
- ),
49
- );
50
- }
51
- };
@@ -1,50 +0,0 @@
1
- import type {
2
- CloudProvider,
3
- ProviderSpecifics,
4
- } from '@remotion/serverless-client';
5
- import {pLimit} from './p-limit';
6
-
7
- const limit = pLimit(10);
8
-
9
- export const cleanItems = <Provider extends CloudProvider>({
10
- bucket,
11
- onAfterItemDeleted,
12
- onBeforeItemDeleted,
13
- region,
14
- list,
15
- providerSpecifics,
16
- forcePathStyle,
17
- requestHandler,
18
- }: {
19
- bucket: string;
20
- region: Provider['region'];
21
- list: string[];
22
- onBeforeItemDeleted: (data: {bucketName: string; itemName: string}) => void;
23
- onAfterItemDeleted: (data: {bucketName: string; itemName: string}) => void;
24
- providerSpecifics: ProviderSpecifics<Provider>;
25
- forcePathStyle: boolean;
26
- requestHandler: Provider['requestHandler'] | null;
27
- }) => {
28
- return Promise.all(
29
- list.map((object) =>
30
- limit(async () => {
31
- onBeforeItemDeleted({
32
- bucketName: bucket,
33
- itemName: object,
34
- });
35
- await providerSpecifics.deleteFile({
36
- bucketName: bucket,
37
- key: object,
38
- region,
39
- customCredentials: null,
40
- forcePathStyle,
41
- requestHandler,
42
- });
43
- onAfterItemDeleted({
44
- bucketName: bucket,
45
- itemName: object,
46
- });
47
- }),
48
- ),
49
- );
50
- };
package/src/constants.ts DELETED
@@ -1,38 +0,0 @@
1
- import type {GenericRenderProgress, Privacy} from '@remotion/serverless-client';
2
- import type {AwsProvider} from './aws-provider';
3
- import type {AwsRegion} from './regions';
4
-
5
- export const MIN_MEMORY = 512;
6
- export const MAX_MEMORY = 10240;
7
- export const DEFAULT_MEMORY_SIZE = 2048;
8
-
9
- export const DEFAULT_TIMEOUT = 120;
10
- export const MIN_TIMEOUT = 15;
11
- export const MAX_TIMEOUT = 900;
12
-
13
- export const DEFAULT_FRAMES_PER_LAMBDA = 20;
14
-
15
- export const BINARY_NAME = 'remotion lambda';
16
- export const DEFAULT_REGION: AwsRegion = 'us-east-1';
17
- export const DEFAULT_MAX_RETRIES = 1;
18
-
19
- export const MAX_EPHEMERAL_STORAGE_IN_MB = 10240;
20
- // TODO: In V5, Enable set this to 10240
21
- export const DEFAULT_EPHEMERAL_STORAGE_IN_MB = 2048;
22
- export const MIN_EPHEMERAL_STORAGE_IN_MB = 512;
23
-
24
- export const DEFAULT_OUTPUT_PRIVACY: Privacy = 'public';
25
-
26
- export const DEFAULT_CLOUDWATCH_RETENTION_PERIOD = 14;
27
-
28
- export const RENDER_FN_PREFIX = 'remotion-render-';
29
- export const LOG_GROUP_PREFIX = '/aws/lambda/';
30
- export const LAMBDA_INSIGHTS_PREFIX = '/aws/lambda-insights';
31
-
32
- export const getSitesKey = (siteId: string) => `sites/${siteId}`;
33
-
34
- export type RenderProgress = GenericRenderProgress<AwsProvider>;
35
-
36
- export const LAMBDA_CONCURRENCY_LIMIT_QUOTA = 'L-B99A9384';
37
-
38
- export const REMOTION_BUCKET_PREFIX = 'remotionlambda-';