@remotion/lambda-client 4.0.390 → 4.0.392

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 (141) hide show
  1. package/dist/app-router-webhook.d.ts +10 -0
  2. package/dist/app-router-webhook.js +43 -0
  3. package/dist/apply-lifecycle.d.ts +8 -0
  4. package/dist/apply-lifecycle.js +18 -0
  5. package/dist/aws-clients.d.ts +12 -0
  6. package/dist/aws-clients.js +56 -0
  7. package/dist/aws-provider.d.ts +27 -0
  8. package/dist/aws-provider.js +94 -0
  9. package/dist/bucket-exists.d.ts +3 -0
  10. package/dist/bucket-exists.js +27 -0
  11. package/dist/call-lambda-async.d.ts +2 -0
  12. package/dist/call-lambda-async.js +20 -0
  13. package/dist/call-lambda-streaming.d.ts +6 -0
  14. package/dist/call-lambda-streaming.js +126 -0
  15. package/dist/call-lambda-sync.d.ts +2 -0
  16. package/dist/call-lambda-sync.js +30 -0
  17. package/dist/check-credentials.d.ts +1 -0
  18. package/dist/check-credentials.js +39 -0
  19. package/dist/cjs/index.js +34 -33
  20. package/dist/clean-items.d.ts +17 -0
  21. package/dist/clean-items.js +26 -0
  22. package/dist/constants.d.ts +25 -0
  23. package/dist/constants.js +26 -0
  24. package/dist/content-disposition-header.d.ts +2 -0
  25. package/dist/content-disposition-header.js +50 -0
  26. package/dist/convert-to-serve-url.d.ts +6 -0
  27. package/dist/convert-to-serve-url.js +14 -0
  28. package/dist/create-bucket.d.ts +3 -0
  29. package/dist/create-bucket.js +65 -0
  30. package/dist/delete-file.d.ts +3 -0
  31. package/dist/delete-file.js +17 -0
  32. package/dist/delete-function.d.ts +7 -0
  33. package/dist/delete-function.js +15 -0
  34. package/dist/delete-render.d.ts +22 -0
  35. package/dist/delete-render.js +90 -0
  36. package/dist/encode-aws-url-params.d.ts +1 -0
  37. package/dist/encode-aws-url-params.js +7 -0
  38. package/dist/esm/index.mjs +21 -20
  39. package/dist/estimate-price.d.ts +17 -0
  40. package/dist/estimate-price.js +45 -0
  41. package/dist/express-webhook.d.ts +3 -0
  42. package/dist/express-webhook.js +46 -0
  43. package/dist/get-account-id.d.ts +3 -0
  44. package/dist/get-account-id.js +15 -0
  45. package/dist/get-aws-client.d.ts +32 -0
  46. package/dist/get-aws-client.js +67 -0
  47. package/dist/get-aws-urls.d.ts +25 -0
  48. package/dist/get-aws-urls.js +31 -0
  49. package/dist/get-buckets.d.ts +9 -0
  50. package/dist/get-buckets.js +64 -0
  51. package/dist/get-compositions-on-lambda.d.ts +20 -0
  52. package/dist/get-compositions-on-lambda.js +62 -0
  53. package/dist/get-credentials.d.ts +9 -0
  54. package/dist/get-credentials.js +55 -0
  55. package/dist/get-env-variable.d.ts +1 -0
  56. package/dist/get-env-variable.js +15 -0
  57. package/dist/get-function-name.d.ts +8 -0
  58. package/dist/get-function-name.js +17 -0
  59. package/dist/get-function-version.d.ts +9 -0
  60. package/dist/get-function-version.js +35 -0
  61. package/dist/get-functions.d.ts +10 -0
  62. package/dist/get-functions.js +80 -0
  63. package/dist/get-output-url-from-metadata.d.ts +3 -0
  64. package/dist/get-output-url-from-metadata.js +18 -0
  65. package/dist/get-render-progress.d.ts +17 -0
  66. package/dist/get-render-progress.js +47 -0
  67. package/dist/get-s3-client.d.ts +11 -0
  68. package/dist/get-s3-client.js +15 -0
  69. package/dist/get-service-client.d.ts +25 -0
  70. package/dist/get-service-client.js +131 -0
  71. package/dist/get-sites.d.ts +31 -0
  72. package/dist/get-sites.js +83 -0
  73. package/dist/head-file.d.ts +3 -0
  74. package/dist/head-file.js +18 -0
  75. package/dist/index.d.ts +129 -0
  76. package/dist/index.js +108 -0
  77. package/dist/is-cli.d.ts +2 -0
  78. package/dist/is-cli.js +10 -0
  79. package/dist/is-flaky-error.d.ts +1 -0
  80. package/dist/is-flaky-error.js +78 -0
  81. package/dist/is-in-lambda.d.ts +1 -0
  82. package/dist/is-in-lambda.js +9 -0
  83. package/dist/is-likely-to-have-aws-profile.d.ts +1 -0
  84. package/dist/is-likely-to-have-aws-profile.js +50 -0
  85. package/dist/lambda-version-string.d.ts +1 -0
  86. package/dist/lambda-version-string.js +7 -0
  87. package/dist/lifecycle-rules.d.ts +12 -0
  88. package/dist/lifecycle-rules.js +73 -0
  89. package/dist/lifecycle.d.ts +7 -0
  90. package/dist/lifecycle.js +24 -0
  91. package/dist/list-objects.d.ts +3 -0
  92. package/dist/list-objects.js +70 -0
  93. package/dist/make-lambda-payload.d.ts +59 -0
  94. package/dist/make-lambda-payload.js +150 -0
  95. package/dist/make-s3-url.d.ts +6 -0
  96. package/dist/make-s3-url.js +7 -0
  97. package/dist/p-limit.d.ts +1 -0
  98. package/dist/p-limit.js +57 -0
  99. package/dist/pages-router-webhook.d.ts +5 -0
  100. package/dist/pages-router-webhook.js +48 -0
  101. package/dist/parse-function-name.d.ts +8 -0
  102. package/dist/parse-function-name.js +17 -0
  103. package/dist/presign-url.d.ts +17 -0
  104. package/dist/presign-url.js +66 -0
  105. package/dist/price-per-1s.d.ts +37 -0
  106. package/dist/price-per-1s.js +822 -0
  107. package/dist/random-hash.d.ts +1 -0
  108. package/dist/random-hash.js +13 -0
  109. package/dist/read-file.d.ts +11 -0
  110. package/dist/read-file.js +19 -0
  111. package/dist/regions.d.ts +3 -0
  112. package/dist/regions.js +48 -0
  113. package/dist/render-media-on-lambda.d.ts +66 -0
  114. package/dist/render-media-on-lambda.js +133 -0
  115. package/dist/render-still-on-lambda.d.ts +61 -0
  116. package/dist/render-still-on-lambda.js +121 -0
  117. package/dist/runtime-preference.d.ts +2 -0
  118. package/dist/runtime-preference.js +8 -0
  119. package/dist/speculate-function-name.d.ts +7 -0
  120. package/dist/speculate-function-name.js +39 -0
  121. package/dist/types.d.ts +4 -0
  122. package/dist/types.js +2 -0
  123. package/dist/validate-aws-region.d.ts +2 -0
  124. package/dist/validate-aws-region.js +9 -0
  125. package/dist/validate-bucketname.d.ts +4 -0
  126. package/dist/validate-bucketname.js +15 -0
  127. package/dist/validate-disk-size-in-mb.d.ts +1 -0
  128. package/dist/validate-disk-size-in-mb.js +23 -0
  129. package/dist/validate-lambda-codec.d.ts +2 -0
  130. package/dist/validate-lambda-codec.js +21 -0
  131. package/dist/validate-memory-size.d.ts +1 -0
  132. package/dist/validate-memory-size.js +22 -0
  133. package/dist/validate-presign-expiration.d.ts +1 -0
  134. package/dist/validate-presign-expiration.js +29 -0
  135. package/dist/validate-serveurl.d.ts +1 -0
  136. package/dist/validate-serveurl.js +9 -0
  137. package/dist/validate-webhook-signature.d.ts +5 -0
  138. package/dist/validate-webhook-signature.js +28 -0
  139. package/dist/write-file.d.ts +5 -0
  140. package/dist/write-file.js +83 -0
  141. package/package.json +3 -3
@@ -0,0 +1,10 @@
1
+ import type { WebhookErrorPayload, WebhookSuccessPayload, WebhookTimeoutPayload } from '@remotion/serverless-client';
2
+ export type NextWebhookArgs = {
3
+ testing?: boolean;
4
+ extraHeaders?: Record<string, string>;
5
+ secret: string;
6
+ onSuccess?: (payload: WebhookSuccessPayload) => void;
7
+ onTimeout?: (payload: WebhookTimeoutPayload) => void;
8
+ onError?: (payload: WebhookErrorPayload) => void;
9
+ };
10
+ export declare const appRouterWebhook: (options: NextWebhookArgs) => ((req: Request) => Promise<Response>);
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.appRouterWebhook = void 0;
4
+ const validate_webhook_signature_1 = require("./validate-webhook-signature");
5
+ const appRouterWebhook = (options) => {
6
+ const { testing, extraHeaders, secret, onSuccess, onTimeout, onError } = options;
7
+ return async function (req) {
8
+ let headers = extraHeaders || {};
9
+ if (testing) {
10
+ const testingheaders = {
11
+ 'Access-Control-Allow-Origin': 'https://www.remotion.dev',
12
+ 'Access-Control-Allow-Headers': 'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version, X-Remotion-Status, X-Remotion-Signature, X-Remotion-Mode',
13
+ 'Access-Control-Allow-Methods': 'OPTIONS,POST',
14
+ };
15
+ headers = { ...headers, ...testingheaders };
16
+ }
17
+ if (req.method === 'OPTIONS') {
18
+ // do we have any use of the OPTIONS method other than the tester on webhooks page ? if so we can add a condition here to only return this if testing mode enabled
19
+ return new Response(null, {
20
+ headers,
21
+ });
22
+ }
23
+ // Parse the body properly
24
+ const body = await req.json();
25
+ (0, validate_webhook_signature_1.validateWebhookSignature)({
26
+ secret,
27
+ body,
28
+ signatureHeader: req.headers.get('X-Remotion-Signature'),
29
+ });
30
+ const payload = body;
31
+ if (payload.type === 'success' && onSuccess) {
32
+ onSuccess(payload);
33
+ }
34
+ else if (payload.type === 'timeout' && onTimeout) {
35
+ onTimeout(payload);
36
+ }
37
+ else if (payload.type === 'error' && onError) {
38
+ onError(payload);
39
+ }
40
+ return new Response(JSON.stringify({ success: true }), { headers });
41
+ };
42
+ };
43
+ exports.appRouterWebhook = appRouterWebhook;
@@ -0,0 +1,8 @@
1
+ import type { DeleteBucketLifecycleCommandInput, LifecycleRule, PutBucketLifecycleConfigurationCommandInput } from '@aws-sdk/client-s3';
2
+ export declare const deleteLifeCycleInput: ({ bucketName, }: {
3
+ bucketName: string;
4
+ }) => DeleteBucketLifecycleCommandInput;
5
+ export declare const createLifeCycleInput: ({ bucketName, lcRules, }: {
6
+ bucketName: string;
7
+ lcRules: LifecycleRule[];
8
+ }) => PutBucketLifecycleConfigurationCommandInput;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createLifeCycleInput = exports.deleteLifeCycleInput = void 0;
4
+ const deleteLifeCycleInput = ({ bucketName, }) => {
5
+ return {
6
+ Bucket: bucketName,
7
+ };
8
+ };
9
+ exports.deleteLifeCycleInput = deleteLifeCycleInput;
10
+ const createLifeCycleInput = ({ bucketName, lcRules, }) => {
11
+ return {
12
+ Bucket: bucketName,
13
+ LifecycleConfiguration: {
14
+ Rules: lcRules,
15
+ },
16
+ };
17
+ };
18
+ exports.createLifeCycleInput = createLifeCycleInput;
@@ -0,0 +1,12 @@
1
+ import type { CloudWatchLogsClient } from '@aws-sdk/client-cloudwatch-logs';
2
+ import type { IAMClient } from '@aws-sdk/client-iam';
3
+ import type { LambdaClient } from '@aws-sdk/client-lambda';
4
+ import type { ServiceQuotasClient } from '@aws-sdk/client-service-quotas';
5
+ import type { STSClient } from '@aws-sdk/client-sts';
6
+ import type { AwsRegion } from './regions';
7
+ import type { RequestHandler } from './types';
8
+ export declare const getCloudWatchLogsClient: (region: AwsRegion, requestHandler: RequestHandler | null) => CloudWatchLogsClient;
9
+ export declare const getLambdaClient: (region: AwsRegion, _timeoutInTest: number | undefined, requestHandler: RequestHandler | null) => LambdaClient;
10
+ export declare const getIamClient: (region: AwsRegion, requestHandler: RequestHandler | null) => IAMClient;
11
+ export declare const getServiceQuotasClient: (region: AwsRegion, requestHandler: RequestHandler | null) => ServiceQuotasClient;
12
+ export declare const getStsClient: (region: AwsRegion, requestHandler: RequestHandler | null) => STSClient;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getStsClient = exports.getServiceQuotasClient = exports.getIamClient = exports.getLambdaClient = exports.getCloudWatchLogsClient = void 0;
4
+ const get_service_client_1 = require("./get-service-client");
5
+ const getCloudWatchLogsClient = (region, requestHandler) => {
6
+ return (0, get_service_client_1.getServiceClient)({
7
+ region,
8
+ service: 'cloudwatch',
9
+ customCredentials: null,
10
+ forcePathStyle: false,
11
+ requestHandler,
12
+ });
13
+ };
14
+ exports.getCloudWatchLogsClient = getCloudWatchLogsClient;
15
+ const getLambdaClient = (region,
16
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
17
+ _timeoutInTest, requestHandler) => {
18
+ return (0, get_service_client_1.getServiceClient)({
19
+ region,
20
+ service: 'lambda',
21
+ customCredentials: null,
22
+ forcePathStyle: false,
23
+ requestHandler,
24
+ });
25
+ };
26
+ exports.getLambdaClient = getLambdaClient;
27
+ const getIamClient = (region, requestHandler) => {
28
+ return (0, get_service_client_1.getServiceClient)({
29
+ region,
30
+ service: 'iam',
31
+ customCredentials: null,
32
+ forcePathStyle: false,
33
+ requestHandler,
34
+ });
35
+ };
36
+ exports.getIamClient = getIamClient;
37
+ const getServiceQuotasClient = (region, requestHandler) => {
38
+ return (0, get_service_client_1.getServiceClient)({
39
+ region,
40
+ service: 'servicequotas',
41
+ customCredentials: null,
42
+ forcePathStyle: false,
43
+ requestHandler,
44
+ });
45
+ };
46
+ exports.getServiceQuotasClient = getServiceQuotasClient;
47
+ const getStsClient = (region, requestHandler) => {
48
+ return (0, get_service_client_1.getServiceClient)({
49
+ region,
50
+ service: 'sts',
51
+ customCredentials: null,
52
+ forcePathStyle: false,
53
+ requestHandler,
54
+ });
55
+ };
56
+ exports.getStsClient = getStsClient;
@@ -0,0 +1,27 @@
1
+ import type { AwsRegion } from './regions';
2
+ export type AwsProvider = {
3
+ type: 'aws';
4
+ region: AwsRegion;
5
+ receivedArtifactType: {
6
+ s3Key: string;
7
+ s3Url: string;
8
+ };
9
+ creationFunctionOptions: {
10
+ createCloudWatchLogGroup: boolean;
11
+ accountId: string;
12
+ alreadyCreated: boolean;
13
+ retentionInDays: number;
14
+ customRoleArn: string;
15
+ enableLambdaInsights: boolean;
16
+ vpcSubnetIds: string;
17
+ vpcSecurityGroupIds: string;
18
+ runtimePreference: RuntimePreference;
19
+ };
20
+ storageClass: StorageClass;
21
+ requestHandler: RequestHandler | null | undefined;
22
+ };
23
+ import type { StorageClass } from '@aws-sdk/client-s3';
24
+ import type { ProviderSpecifics } from '@remotion/serverless-client';
25
+ import type { RuntimePreference } from './runtime-preference';
26
+ import type { RequestHandler } from './types';
27
+ export declare const awsImplementation: ProviderSpecifics<AwsProvider>;
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.awsImplementation = void 0;
5
+ const serverless_client_1 = require("@remotion/serverless-client");
6
+ const node_events_1 = require("node:events");
7
+ const bucket_exists_1 = require("./bucket-exists");
8
+ const call_lambda_async_1 = require("./call-lambda-async");
9
+ const call_lambda_streaming_1 = require("./call-lambda-streaming");
10
+ const call_lambda_sync_1 = require("./call-lambda-sync");
11
+ const check_credentials_1 = require("./check-credentials");
12
+ const constants_1 = require("./constants");
13
+ const convert_to_serve_url_1 = require("./convert-to-serve-url");
14
+ const create_bucket_1 = require("./create-bucket");
15
+ const delete_file_1 = require("./delete-file");
16
+ const delete_function_1 = require("./delete-function");
17
+ const estimate_price_1 = require("./estimate-price");
18
+ const get_account_id_1 = require("./get-account-id");
19
+ const get_aws_urls_1 = require("./get-aws-urls");
20
+ const get_buckets_1 = require("./get-buckets");
21
+ const get_functions_1 = require("./get-functions");
22
+ const get_output_url_from_metadata_1 = require("./get-output-url-from-metadata");
23
+ const head_file_1 = require("./head-file");
24
+ const is_flaky_error_1 = require("./is-flaky-error");
25
+ const lifecycle_rules_1 = require("./lifecycle-rules");
26
+ const list_objects_1 = require("./list-objects");
27
+ const parse_function_name_1 = require("./parse-function-name");
28
+ const random_hash_1 = require("./random-hash");
29
+ const read_file_1 = require("./read-file");
30
+ const write_file_1 = require("./write-file");
31
+ if (/^AWS_Lambda_nodejs(?:18|20)[.]x$/.test((_a = process.env.AWS_EXECUTION_ENV) !== null && _a !== void 0 ? _a : '') === true) {
32
+ process.env.FONTCONFIG_PATH = '/opt';
33
+ process.env.FONTCONFIG_FILE = '/opt/fonts.conf';
34
+ process.env.DISABLE_FROM_SURFACE = '1';
35
+ process.env.NO_COLOR = '1';
36
+ // @ts-expect-error
37
+ globalThis._dumpUnreleasedBuffers = new node_events_1.EventEmitter();
38
+ // @ts-expect-error
39
+ globalThis._dumpUnreleasedBuffers.setMaxListeners(201);
40
+ }
41
+ const validateDeleteAfter = (lifeCycleValue) => {
42
+ if (lifeCycleValue === null) {
43
+ return;
44
+ }
45
+ if (lifeCycleValue === undefined) {
46
+ return;
47
+ }
48
+ if (typeof lifeCycleValue !== 'string') {
49
+ throw new TypeError(`Expected life cycle value to be a string, got ${JSON.stringify(lifeCycleValue)}`);
50
+ }
51
+ if (!(lifeCycleValue in serverless_client_1.expiryDays)) {
52
+ throw new TypeError(`Expected deleteAfter value to be one of ${Object.keys(serverless_client_1.expiryDays).join(', ')}, got ${lifeCycleValue}`);
53
+ }
54
+ };
55
+ exports.awsImplementation = {
56
+ getChromiumPath() {
57
+ return '/opt/bin/chromium';
58
+ },
59
+ getBuckets: get_buckets_1.getRemotionBuckets,
60
+ createBucket: create_bucket_1.createBucket,
61
+ applyLifeCycle: lifecycle_rules_1.applyLifeCyleOperation,
62
+ listObjects: list_objects_1.lambdaLsImplementation,
63
+ deleteFile: delete_file_1.lambdaDeleteFileImplementation,
64
+ bucketExists: bucket_exists_1.bucketExistsInRegionImplementation,
65
+ randomHash: random_hash_1.randomHashImplementation,
66
+ readFile: read_file_1.lambdaReadFileImplementation,
67
+ writeFile: write_file_1.lambdaWriteFileImplementation,
68
+ headFile: head_file_1.lambdaHeadFileImplementation,
69
+ convertToServeUrl: convert_to_serve_url_1.convertToServeUrlImplementation,
70
+ printLoggingHelper: true,
71
+ validateDeleteAfter,
72
+ callFunctionAsync: call_lambda_async_1.callFunctionAsyncImplementation,
73
+ callFunctionStreaming: call_lambda_streaming_1.callFunctionWithStreamingImplementation,
74
+ callFunctionSync: call_lambda_sync_1.callFunctionSyncImplementation,
75
+ getEphemeralStorageForPriceCalculation() {
76
+ // We cannot determine the ephemeral storage size, so we
77
+ // overestimate the price, but will only have a miniscule effect (~0.2%)
78
+ return constants_1.MAX_EPHEMERAL_STORAGE_IN_MB;
79
+ },
80
+ estimatePrice: estimate_price_1.estimatePrice,
81
+ getLoggingUrlForMethod: get_aws_urls_1.getCloudwatchMethodUrl,
82
+ getLoggingUrlForRendererFunction: get_aws_urls_1.getCloudwatchRendererUrl,
83
+ isFlakyError: is_flaky_error_1.isFlakyError,
84
+ getOutputUrl: get_output_url_from_metadata_1.getOutputUrlFromMetadata,
85
+ serverStorageProductName: () => 'S3',
86
+ getMaxStillInlinePayloadSize: () => 5000000,
87
+ getMaxNonInlinePayloadSizePerFunction: () => 200000,
88
+ getAccountId: get_account_id_1.getAccountIdImplementation,
89
+ deleteFunction: delete_function_1.deleteFunction,
90
+ getFunctions: get_functions_1.getFunctions,
91
+ parseFunctionName: parse_function_name_1.parseFunctionName,
92
+ checkCredentials: check_credentials_1.checkCredentials,
93
+ getBucketPrefix: () => constants_1.REMOTION_BUCKET_PREFIX,
94
+ };
@@ -0,0 +1,3 @@
1
+ import type { ProviderSpecifics } from '@remotion/serverless-client';
2
+ import type { AwsProvider } from './aws-provider';
3
+ export declare const bucketExistsInRegionImplementation: ProviderSpecifics<AwsProvider>['bucketExists'];
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bucketExistsInRegionImplementation = void 0;
4
+ const client_s3_1 = require("@aws-sdk/client-s3");
5
+ const get_s3_client_1 = require("./get-s3-client");
6
+ const bucketExistsInRegionImplementation = async ({ bucketName, region, expectedBucketOwner, forcePathStyle, requestHandler, }) => {
7
+ var _a;
8
+ try {
9
+ const bucket = await (0, get_s3_client_1.getS3Client)({
10
+ region,
11
+ customCredentials: null,
12
+ forcePathStyle,
13
+ requestHandler,
14
+ }).send(new client_s3_1.GetBucketLocationCommand({
15
+ Bucket: bucketName,
16
+ ExpectedBucketOwner: expectedBucketOwner !== null && expectedBucketOwner !== void 0 ? expectedBucketOwner : undefined,
17
+ }));
18
+ return ((_a = bucket.LocationConstraint) !== null && _a !== void 0 ? _a : 'us-east-1') === region;
19
+ }
20
+ catch (err) {
21
+ if (err.Code === 'NoSuchBucket') {
22
+ return false;
23
+ }
24
+ throw err;
25
+ }
26
+ };
27
+ exports.bucketExistsInRegionImplementation = bucketExistsInRegionImplementation;
@@ -0,0 +1,2 @@
1
+ import type { CallFunctionOptions, CloudProvider, ServerlessRoutines } from '@remotion/serverless-client';
2
+ export declare const callFunctionAsyncImplementation: <T extends ServerlessRoutines, Provider extends CloudProvider>({ functionName, payload, region, timeoutInTest, }: CallFunctionOptions<T, Provider>) => Promise<void>;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.callFunctionAsyncImplementation = void 0;
4
+ const client_lambda_1 = require("@aws-sdk/client-lambda");
5
+ const aws_clients_1 = require("./aws-clients");
6
+ const callFunctionAsyncImplementation = async ({ functionName, payload, region, timeoutInTest, }) => {
7
+ const stringifiedPayload = JSON.stringify(payload);
8
+ if (stringifiedPayload.length > 256 * 1024) {
9
+ throw new Error(`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}`);
10
+ }
11
+ const result = await (0, aws_clients_1.getLambdaClient)(region, timeoutInTest, null).send(new client_lambda_1.InvokeCommand({
12
+ FunctionName: functionName,
13
+ Payload: stringifiedPayload,
14
+ InvocationType: 'Event',
15
+ }));
16
+ if (result.FunctionError) {
17
+ throw new Error(`Lambda function returned error: ${result.FunctionError} ${result.LogResult}`);
18
+ }
19
+ };
20
+ exports.callFunctionAsyncImplementation = callFunctionAsyncImplementation;
@@ -0,0 +1,6 @@
1
+ import type { CallFunctionOptions, CloudProvider, OnMessage, ServerlessRoutines } from '@remotion/serverless-client';
2
+ export declare const parseJsonOrThrowSource: (data: Uint8Array, type: string) => any;
3
+ export declare const callFunctionWithStreamingImplementation: <Provider extends CloudProvider, T extends ServerlessRoutines>(options: CallFunctionOptions<T, Provider> & {
4
+ receivedStreamingPayload: OnMessage<Provider>;
5
+ retriesRemaining: number;
6
+ }) => Promise<void>;
@@ -0,0 +1,126 @@
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 serverless_client_1 = require("@remotion/serverless-client");
6
+ const aws_clients_1 = require("./aws-clients");
7
+ const STREAM_STALL_TIMEOUT = 30000;
8
+ const LAMBDA_STREAM_STALL = `AWS did not invoke Lambda in ${STREAM_STALL_TIMEOUT}ms`;
9
+ const parseJsonOrThrowSource = (data, type) => {
10
+ const asString = new TextDecoder('utf-8').decode(data);
11
+ try {
12
+ return JSON.parse(asString);
13
+ }
14
+ catch (_a) {
15
+ throw new Error(`Invalid JSON (${type}): ${asString}`);
16
+ }
17
+ };
18
+ exports.parseJsonOrThrowSource = parseJsonOrThrowSource;
19
+ const invokeStreamOrTimeout = async ({ region, timeoutInTest, functionName, type, payload, }) => {
20
+ const resProm = (0, aws_clients_1.getLambdaClient)(region, timeoutInTest, null).send(new client_lambda_1.InvokeWithResponseStreamCommand({
21
+ FunctionName: functionName,
22
+ Payload: JSON.stringify({ type, ...payload }),
23
+ }));
24
+ let cleanup = () => undefined;
25
+ const timeout = new Promise((_resolve, reject) => {
26
+ const int = setTimeout(() => {
27
+ reject(new Error(LAMBDA_STREAM_STALL));
28
+ }, STREAM_STALL_TIMEOUT);
29
+ cleanup = () => {
30
+ clearTimeout(int);
31
+ };
32
+ });
33
+ const res = await Promise.race([resProm, timeout]);
34
+ cleanup();
35
+ return res;
36
+ };
37
+ const INVALID_JSON_MESSAGE = 'Cannot parse Lambda response as JSON';
38
+ const callLambdaWithStreamingWithoutRetry = async ({ functionName, type, payload, region, timeoutInTest, receivedStreamingPayload, }) => {
39
+ const res = await invokeStreamOrTimeout({
40
+ functionName,
41
+ payload,
42
+ region,
43
+ timeoutInTest,
44
+ type,
45
+ });
46
+ const { onData, clear } = (0, serverless_client_1.makeStreamer)((status, messageTypeId, data) => {
47
+ const messageType = (0, serverless_client_1.messageTypeIdToMessageType)(messageTypeId);
48
+ const innerPayload = serverless_client_1.formatMap[messageType] === 'json'
49
+ ? (0, exports.parseJsonOrThrowSource)(data, messageType)
50
+ : data;
51
+ const message = {
52
+ successType: status,
53
+ message: {
54
+ type: messageType,
55
+ payload: innerPayload,
56
+ },
57
+ };
58
+ receivedStreamingPayload(message);
59
+ });
60
+ const dumpBuffers = () => {
61
+ clear();
62
+ };
63
+ // @ts-expect-error - We are adding a listener to a global variable
64
+ if (globalThis._dumpUnreleasedBuffers) {
65
+ // @ts-expect-error - We are adding a listener to a global variable
66
+ globalThis._dumpUnreleasedBuffers.addListener('dump-unreleased-buffers', dumpBuffers);
67
+ }
68
+ const events = res.EventStream;
69
+ for await (const event of events) {
70
+ // There are two types of events you can get on a stream.
71
+ // `PayloadChunk`: These contain the actual raw bytes of the chunk
72
+ // It has a single property: `Payload`
73
+ if (event.PayloadChunk && event.PayloadChunk.Payload) {
74
+ onData(event.PayloadChunk.Payload);
75
+ }
76
+ if (event.InvokeComplete) {
77
+ if (event.InvokeComplete.ErrorCode) {
78
+ 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}))`;
79
+ if (event.InvokeComplete.ErrorCode === 'Unhandled') {
80
+ throw new Error(`Lambda function ${functionName} failed with an unhandled error: ${event.InvokeComplete.ErrorDetails} See ${logs} to see the logs of this invocation.`);
81
+ }
82
+ 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.`);
83
+ }
84
+ }
85
+ // Don't put a `break` statement here, as it will cause the socket to not properly exit.
86
+ }
87
+ // @ts-expect-error - We are adding a listener to a global variable
88
+ if (globalThis._dumpUnreleasedBuffers) {
89
+ // @ts-expect-error - We are adding a listener to a global variable
90
+ globalThis._dumpUnreleasedBuffers.removeListener('dump-unreleased-buffers', dumpBuffers);
91
+ }
92
+ clear();
93
+ };
94
+ const callFunctionWithStreamingImplementation = async (options) => {
95
+ // As of August 2023, Lambda streaming sometimes misses parts of the JSON response.
96
+ // Handling this for now by applying a retry mechanism.
97
+ var _a, _b;
98
+ try {
99
+ // Do not remove this await
100
+ await callLambdaWithStreamingWithoutRetry(options);
101
+ }
102
+ catch (err) {
103
+ if (((_a = err.stack) === null || _a === void 0 ? void 0 : _a.includes('TooManyRequestsException')) ||
104
+ ((_b = err.message) === null || _b === void 0 ? void 0 : _b.includes('ConcurrentInvocationLimitExceeded'))) {
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
+ // https://discord.com/channels/809501355504959528/1332166561242288220/1332166561242288220
110
+ !err.message.includes('Runtime.TruncatedResponse') &&
111
+ !err.message.includes('aborted')) {
112
+ throw err;
113
+ }
114
+ console.error('Retries remaining:', options.retriesRemaining);
115
+ if (options.retriesRemaining === 0) {
116
+ console.error('Throwing error:');
117
+ throw err;
118
+ }
119
+ console.error(err);
120
+ return (0, exports.callFunctionWithStreamingImplementation)({
121
+ ...options,
122
+ retriesRemaining: options.retriesRemaining - 1,
123
+ });
124
+ }
125
+ };
126
+ exports.callFunctionWithStreamingImplementation = callFunctionWithStreamingImplementation;
@@ -0,0 +1,2 @@
1
+ import type { CallFunctionOptions, CloudProvider, ServerlessReturnValues, ServerlessRoutines } from '@remotion/serverless-client';
2
+ 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, null).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;
@@ -0,0 +1 @@
1
+ export declare const checkCredentials: () => void;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkCredentials = void 0;
4
+ const serverless_client_1 = require("@remotion/serverless-client");
5
+ const get_env_variable_1 = require("./get-env-variable");
6
+ const is_cli_1 = require("./is-cli");
7
+ const is_likely_to_have_aws_profile_1 = require("./is-likely-to-have-aws-profile");
8
+ const messageForVariable = (variable) => {
9
+ return [
10
+ `You have tried to call a Remotion Lambda function, but have not set the environment variable ${variable}.`,
11
+ (0, is_cli_1.getIsCli)()
12
+ ? null
13
+ : `- 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.`,
14
+ `- Please refer to the Remotion Lambda docs (${serverless_client_1.DOCS_URL}/docs/lambda/setup) to see how to generate the credentials for your AWS account and then set the environment variables.`,
15
+ `- For more reasons see the troubleshooting page: ${serverless_client_1.DOCS_URL}/docs/lambda/troubleshooting/permissions`,
16
+ ]
17
+ .filter(serverless_client_1.truthy)
18
+ .join('\n');
19
+ };
20
+ const checkCredentials = () => {
21
+ if ((0, get_env_variable_1.getEnvVariable)('REMOTION_SKIP_AWS_CREDENTIALS_CHECK')) {
22
+ return;
23
+ }
24
+ if ((0, get_env_variable_1.getEnvVariable)('REMOTION_AWS_PROFILE') || (0, get_env_variable_1.getEnvVariable)('AWS_PROFILE')) {
25
+ return;
26
+ }
27
+ if ((0, is_likely_to_have_aws_profile_1.isLikelyToHaveAwsProfile)()) {
28
+ return;
29
+ }
30
+ if (!(0, get_env_variable_1.getEnvVariable)('AWS_ACCESS_KEY_ID') &&
31
+ !(0, get_env_variable_1.getEnvVariable)('REMOTION_AWS_ACCESS_KEY_ID')) {
32
+ throw new Error(messageForVariable('AWS_ACCESS_KEY_ID or REMOTION_AWS_ACCESS_KEY_ID'));
33
+ }
34
+ if (!(0, get_env_variable_1.getEnvVariable)('AWS_SECRET_ACCESS_KEY') &&
35
+ !(0, get_env_variable_1.getEnvVariable)('REMOTION_AWS_SECRET_ACCESS_KEY')) {
36
+ throw new Error(messageForVariable('AWS_SECRET_ACCESS_KEY or REMOTION_AWS_SECRET_ACCESS_KEY'));
37
+ }
38
+ };
39
+ exports.checkCredentials = checkCredentials;