@remotion/lambda-client 4.0.364 → 4.0.366

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 (103) hide show
  1. package/dist/cjs/index.js +1 -1
  2. package/dist/esm/index.mjs +1 -1
  3. package/package.json +4 -4
  4. package/.turbo/turbo-formatting.log +0 -4
  5. package/.turbo/turbo-lint.log +0 -25
  6. package/.turbo/turbo-make.log +0 -3
  7. package/bundle.ts +0 -20
  8. package/dist/cjs/test/concurrency-payload.test.d.ts +0 -1
  9. package/dist/cjs/test/encode-aws-url.test.d.ts +0 -1
  10. package/dist/cjs/test/price-calculation.test.d.ts +0 -1
  11. package/dist/cjs/test/pricing.test.d.ts +0 -1
  12. package/dist/cjs/test/request-handler.test.d.ts +0 -1
  13. package/dist/cjs/test/validate-disk-size-in-mb.test.d.ts +0 -1
  14. package/dist/test/concurrency-payload.test.d.ts +0 -1
  15. package/dist/test/concurrency-payload.test.js +0 -119
  16. package/dist/test/encode-aws-url.test.d.ts +0 -1
  17. package/dist/test/encode-aws-url.test.js +0 -8
  18. package/dist/test/price-calculation.test.d.ts +0 -1
  19. package/dist/test/price-calculation.test.js +0 -62
  20. package/dist/test/pricing.test.d.ts +0 -1
  21. package/dist/test/pricing.test.js +0 -27
  22. package/dist/test/request-handler.test.d.ts +0 -1
  23. package/dist/test/request-handler.test.js +0 -36
  24. package/dist/test/validate-disk-size-in-mb.test.d.ts +0 -1
  25. package/dist/test/validate-disk-size-in-mb.test.js +0 -14
  26. package/dist/tsconfig.tsbuildinfo +0 -1
  27. package/eslint.config.mjs +0 -5
  28. package/src/app-router-webhook.ts +0 -73
  29. package/src/apply-lifecycle.ts +0 -30
  30. package/src/aws-clients.ts +0 -75
  31. package/src/aws-provider.ts +0 -139
  32. package/src/bucket-exists.ts +0 -35
  33. package/src/call-lambda-async.ts +0 -43
  34. package/src/call-lambda-streaming.ts +0 -226
  35. package/src/call-lambda-sync.ts +0 -59
  36. package/src/check-credentials.ts +0 -51
  37. package/src/clean-items.ts +0 -50
  38. package/src/constants.ts +0 -38
  39. package/src/content-disposition-header.ts +0 -64
  40. package/src/convert-to-serve-url.ts +0 -24
  41. package/src/create-bucket.ts +0 -87
  42. package/src/delete-file.ts +0 -38
  43. package/src/delete-function.ts +0 -28
  44. package/src/delete-render.ts +0 -114
  45. package/src/encode-aws-url-params.ts +0 -3
  46. package/src/estimate-price.ts +0 -95
  47. package/src/express-webhook.ts +0 -57
  48. package/src/get-account-id.ts +0 -22
  49. package/src/get-aws-client.ts +0 -63
  50. package/src/get-aws-urls.ts +0 -85
  51. package/src/get-buckets.ts +0 -84
  52. package/src/get-compositions-on-lambda.ts +0 -111
  53. package/src/get-credentials.ts +0 -81
  54. package/src/get-env-variable.ts +0 -15
  55. package/src/get-function-name.ts +0 -24
  56. package/src/get-function-version.ts +0 -49
  57. package/src/get-functions.ts +0 -114
  58. package/src/get-output-url-from-metadata.ts +0 -23
  59. package/src/get-render-progress.ts +0 -66
  60. package/src/get-s3-client.ts +0 -26
  61. package/src/get-service-client.ts +0 -195
  62. package/src/get-sites.ts +0 -136
  63. package/src/head-file.ts +0 -30
  64. package/src/index.ts +0 -152
  65. package/src/is-cli.ts +0 -7
  66. package/src/is-flaky-error.ts +0 -104
  67. package/src/is-in-lambda.ts +0 -5
  68. package/src/is-likely-to-have-aws-profile.ts +0 -55
  69. package/src/lambda-version-string.ts +0 -5
  70. package/src/lifecycle-rules.ts +0 -119
  71. package/src/lifecycle.ts +0 -44
  72. package/src/list-objects.ts +0 -87
  73. package/src/make-lambda-payload.ts +0 -328
  74. package/src/make-s3-url.ts +0 -13
  75. package/src/p-limit.ts +0 -75
  76. package/src/pages-router-webhook.ts +0 -68
  77. package/src/parse-function-name.ts +0 -24
  78. package/src/presign-url.ts +0 -121
  79. package/src/price-per-1s.ts +0 -863
  80. package/src/random-hash.ts +0 -10
  81. package/src/read-file.ts +0 -35
  82. package/src/regions.ts +0 -48
  83. package/src/render-media-on-lambda.ts +0 -227
  84. package/src/render-still-on-lambda.ts +0 -209
  85. package/src/runtime-preference.ts +0 -7
  86. package/src/speculate-function-name.ts +0 -60
  87. package/src/test/concurrency-payload.test.ts +0 -121
  88. package/src/test/encode-aws-url.test.ts +0 -7
  89. package/src/test/price-calculation.test.ts +0 -62
  90. package/src/test/pricing.test.ts +0 -32
  91. package/src/test/request-handler.test.ts +0 -42
  92. package/src/test/validate-disk-size-in-mb.test.ts +0 -15
  93. package/src/types.ts +0 -7
  94. package/src/validate-aws-region.ts +0 -14
  95. package/src/validate-bucketname.ts +0 -24
  96. package/src/validate-disk-size-in-mb.ts +0 -37
  97. package/src/validate-lambda-codec.ts +0 -28
  98. package/src/validate-memory-size.ts +0 -31
  99. package/src/validate-presign-expiration.ts +0 -46
  100. package/src/validate-serveurl.ts +0 -9
  101. package/src/validate-webhook-signature.ts +0 -42
  102. package/src/write-file.ts +0 -108
  103. package/tsconfig.json +0 -10
@@ -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-';
@@ -1,64 +0,0 @@
1
- import type {DownloadBehavior} from '@remotion/serverless-client';
2
-
3
- // By setting the Content-Disposition header in an S3 object,
4
- // you can control if the user downloads the item if you
5
- // visit the link
6
-
7
- const problematicCharacters = {
8
- '%3A': ':',
9
- '%2F': '/',
10
- '%3F': '?',
11
- '%23': '#',
12
- '%5B': '[',
13
- '%5D': ']',
14
- '%40': '@',
15
- '%21': '!',
16
- '%24': '$',
17
- '%26': '&',
18
- '%27': "'",
19
- '%28': '(',
20
- '%29': ')',
21
- '%2A': '*',
22
- '%2B': '+',
23
- '%2C': ',',
24
- '%3B': ';',
25
- };
26
-
27
- type HexInfo = {
28
- containsHex: boolean;
29
- };
30
-
31
- const includesHexOfUnsafeChar = (path: string): HexInfo => {
32
- for (const key of Object.keys(
33
- problematicCharacters,
34
- ) as (keyof typeof problematicCharacters)[]) {
35
- if (path.includes(key)) {
36
- return {containsHex: true};
37
- }
38
- }
39
-
40
- return {containsHex: false};
41
- };
42
-
43
- export const getContentDispositionHeader = (
44
- behavior: DownloadBehavior | null,
45
- ): string | undefined => {
46
- if (behavior === null) {
47
- return undefined;
48
- }
49
-
50
- if (behavior.type === 'play-in-browser') {
51
- return undefined;
52
- }
53
-
54
- if (behavior.fileName === null) {
55
- return `attachment`;
56
- }
57
-
58
- const {containsHex} = includesHexOfUnsafeChar(behavior.fileName);
59
- if (containsHex) {
60
- return `attachment; filename="${behavior.fileName}"`;
61
- }
62
-
63
- return `attachment; filename="${encodeURIComponent(behavior.fileName)}"`;
64
- };
@@ -1,24 +0,0 @@
1
- import {DOCS_URL} from '@remotion/serverless-client';
2
- import type {AwsRegion} from './regions';
3
-
4
- export const convertToServeUrlImplementation = ({
5
- urlOrId,
6
- region,
7
- bucketName,
8
- }: {
9
- urlOrId: string;
10
- region: AwsRegion;
11
- bucketName: string;
12
- }) => {
13
- if (urlOrId.startsWith('src/')) {
14
- throw new Error(
15
- `Remotion Lambda can only render based on a URL in the cloud. It seems like you passed a local file: ${urlOrId}. Read the setup guide for Remotion Lambda ${DOCS_URL}/docs/lambda/setup`,
16
- );
17
- }
18
-
19
- if (urlOrId.startsWith('http://') || urlOrId.startsWith('https://')) {
20
- return urlOrId;
21
- }
22
-
23
- return `https://${bucketName}.s3.${region}.amazonaws.com/sites/${urlOrId}/index.html`;
24
- };
@@ -1,87 +0,0 @@
1
- import {
2
- CreateBucketCommand,
3
- DeleteBucketOwnershipControlsCommand,
4
- DeletePublicAccessBlockCommand,
5
- PutBucketAclCommand,
6
- } from '@aws-sdk/client-s3';
7
- import type {ProviderSpecifics} from '@remotion/serverless-client';
8
- import type {AwsProvider} from './aws-provider';
9
- import {getS3Client} from './get-s3-client';
10
-
11
- export const createBucket: ProviderSpecifics<AwsProvider>['createBucket'] =
12
- async ({region, bucketName, forcePathStyle, requestHandler}) => {
13
- await getS3Client({
14
- region,
15
- customCredentials: null,
16
- forcePathStyle,
17
- requestHandler,
18
- }).send(
19
- new CreateBucketCommand({
20
- Bucket: bucketName,
21
- }),
22
- );
23
-
24
- try {
25
- await getS3Client({
26
- region,
27
- customCredentials: null,
28
- forcePathStyle,
29
- requestHandler,
30
- }).send(
31
- new DeleteBucketOwnershipControlsCommand({
32
- Bucket: bucketName,
33
- }),
34
- );
35
- } catch (err) {
36
- if ((err as Error).message.includes('Access Denied')) {
37
- throw new Error(
38
- 'Since April 2023, more AWS permissions are required to create an S3 bucket. You need to update your user policy to continue. See https://remotion.dev/docs/lambda/s3-public-access for instructions on how to resolve this issue.',
39
- );
40
- }
41
-
42
- throw err;
43
- }
44
-
45
- try {
46
- await getS3Client({
47
- region,
48
- customCredentials: null,
49
- forcePathStyle,
50
- requestHandler,
51
- }).send(
52
- new DeletePublicAccessBlockCommand({
53
- Bucket: bucketName,
54
- }),
55
- );
56
- } catch (err) {
57
- if ((err as Error).message.includes('Access Denied')) {
58
- throw new Error(
59
- 'PARTIAL SUCCESS: The s3:PutBucketOwnershipControls was found, but the s3:PutBucketPublicAccessBlock permission is not given. Since April 2023, more AWS permissions are required to create an S3 bucket. You need to update your user policy to continue. You need to update your user policy to continue. See https://remotion.dev/docs/lambda/s3-public-access for instructions on how to resolve this issue.',
60
- );
61
- }
62
-
63
- throw err;
64
- }
65
-
66
- try {
67
- await getS3Client({
68
- region,
69
- customCredentials: null,
70
- forcePathStyle,
71
- requestHandler,
72
- }).send(
73
- new PutBucketAclCommand({
74
- Bucket: bucketName,
75
- ACL: 'public-read',
76
- }),
77
- );
78
- } catch (err) {
79
- if ((err as Error).message.includes('The bucket does not allow ACLs')) {
80
- throw new Error(
81
- `Could not add an ACL to the bucket. This might have happened because the bucket was already successfully created before but then failed to configure correctly. We recommend to delete the bucket (${bucketName}) if it is empty and start over to fix the problem.`,
82
- );
83
- }
84
-
85
- throw err;
86
- }
87
- };
@@ -1,38 +0,0 @@
1
- import {DeleteObjectCommand} from '@aws-sdk/client-s3';
2
- import type {
3
- CustomCredentials,
4
- ProviderSpecifics,
5
- } from '@remotion/serverless-client';
6
- import type {AwsProvider} from './aws-provider';
7
- import {getS3Client} from './get-s3-client';
8
- import type {AwsRegion} from './regions';
9
- import type {RequestHandler} from './types';
10
-
11
- export const lambdaDeleteFileImplementation: ProviderSpecifics<AwsProvider>['deleteFile'] =
12
- async ({
13
- bucketName,
14
- key,
15
- region,
16
- customCredentials,
17
- forcePathStyle,
18
- requestHandler,
19
- }: {
20
- region: AwsRegion;
21
- bucketName: string;
22
- key: string;
23
- customCredentials: CustomCredentials<AwsProvider> | null;
24
- forcePathStyle: boolean;
25
- requestHandler: RequestHandler | null;
26
- }) => {
27
- await getS3Client({
28
- region,
29
- customCredentials,
30
- forcePathStyle,
31
- requestHandler,
32
- }).send(
33
- new DeleteObjectCommand({
34
- Bucket: bucketName,
35
- Key: key,
36
- }),
37
- );
38
- };
@@ -1,28 +0,0 @@
1
- import {DeleteFunctionCommand} from '@aws-sdk/client-lambda';
2
- import type {
3
- DeleteFunction,
4
- DeleteFunctionInput as GenericDeleteFunctionInput,
5
- } from '@remotion/serverless-client';
6
- import {getLambdaClient} from './aws-clients';
7
- import type {AwsProvider} from './aws-provider';
8
- import type {RequestHandler} from './types';
9
-
10
- export type DeleteFunctionInput = GenericDeleteFunctionInput<AwsProvider> & {
11
- requestHandler?: RequestHandler;
12
- };
13
-
14
- /*
15
- * @description Deletes a deployed Lambda function based on its name.
16
- * @see [Documentation](https://remotion.dev/docs/lambda/deletefunction)
17
- */
18
- export const deleteFunction: DeleteFunction<AwsProvider> = async ({
19
- region,
20
- functionName,
21
- requestHandler,
22
- }: DeleteFunctionInput): Promise<void> => {
23
- await getLambdaClient(region, undefined, requestHandler ?? null).send(
24
- new DeleteFunctionCommand({
25
- FunctionName: functionName,
26
- }),
27
- );
28
- };
@@ -1,114 +0,0 @@
1
- import type {ProviderSpecifics} from '@remotion/serverless-client';
2
- import {
3
- getExpectedOutName,
4
- getOverallProgressFromStorage,
5
- rendersPrefix,
6
- type CustomCredentials,
7
- } from '@remotion/serverless-client';
8
- import type {AwsProvider} from './aws-provider';
9
- import {awsImplementation} from './aws-provider';
10
- import {cleanItems} from './clean-items';
11
- import {REMOTION_BUCKET_PREFIX} from './constants';
12
- import type {AwsRegion} from './regions';
13
- import type {RequestHandler} from './types';
14
-
15
- export type DeleteRenderInput = {
16
- region: AwsRegion;
17
- bucketName: string;
18
- renderId: string;
19
- customCredentials?: CustomCredentials<AwsProvider>;
20
- forcePathStyle?: boolean;
21
- requestHandler?: RequestHandler;
22
- };
23
-
24
- export const internalDeleteRender = async (
25
- input: DeleteRenderInput & {
26
- providerSpecifics: ProviderSpecifics<AwsProvider>;
27
- forcePathStyle: boolean;
28
- },
29
- ) => {
30
- const expectedBucketOwner = await input.providerSpecifics.getAccountId({
31
- region: input.region,
32
- });
33
- const progress = await getOverallProgressFromStorage({
34
- bucketName: input.bucketName,
35
- expectedBucketOwner,
36
- region: input.region,
37
- renderId: input.renderId,
38
- providerSpecifics: input.providerSpecifics,
39
- forcePathStyle: input.forcePathStyle,
40
- requestHandler: input.requestHandler,
41
- });
42
-
43
- // Render did not start yet
44
- if (progress.renderMetadata === null) {
45
- return {freedBytes: 0};
46
- }
47
-
48
- const {key, renderBucketName, customCredentials} = getExpectedOutName({
49
- renderMetadata: progress.renderMetadata,
50
- bucketName: input.bucketName,
51
- customCredentials: input.customCredentials ?? null,
52
- bucketNamePrefix: REMOTION_BUCKET_PREFIX,
53
- });
54
-
55
- await input.providerSpecifics.deleteFile({
56
- bucketName: renderBucketName,
57
- customCredentials,
58
- key,
59
- region: input.region,
60
- forcePathStyle: input.forcePathStyle,
61
- requestHandler: input.requestHandler,
62
- });
63
-
64
- let files = await input.providerSpecifics.listObjects({
65
- bucketName: input.bucketName,
66
- prefix: rendersPrefix(input.renderId),
67
- region: input.region,
68
- expectedBucketOwner,
69
- forcePathStyle: input.forcePathStyle,
70
- requestHandler: input.requestHandler,
71
- });
72
-
73
- let totalSize = 0;
74
-
75
- while (files.length > 0) {
76
- totalSize += files.reduce((a, b) => {
77
- return a + (b.Size ?? 0);
78
- }, 0);
79
- await cleanItems({
80
- list: files.map((f) => f.Key as string),
81
- bucket: input.bucketName,
82
- onAfterItemDeleted: () => undefined,
83
- onBeforeItemDeleted: () => undefined,
84
- region: input.region,
85
- providerSpecifics: input.providerSpecifics,
86
- forcePathStyle: input.forcePathStyle,
87
- requestHandler: input.requestHandler,
88
- });
89
- files = await input.providerSpecifics.listObjects({
90
- bucketName: input.bucketName,
91
- prefix: rendersPrefix(input.renderId),
92
- region: input.region,
93
- expectedBucketOwner,
94
- forcePathStyle: input.forcePathStyle,
95
- requestHandler: input.requestHandler,
96
- });
97
- }
98
-
99
- return {
100
- freedBytes: totalSize,
101
- };
102
- };
103
-
104
- /*
105
- * @description Deletes a rendered video, audio or still and its associated metadata.
106
- * @see [Documentation](https://remotion.dev/docs/lambda/deleterender)
107
- */
108
- export const deleteRender = (input: DeleteRenderInput) => {
109
- return internalDeleteRender({
110
- ...input,
111
- providerSpecifics: awsImplementation,
112
- forcePathStyle: input.forcePathStyle ?? false,
113
- });
114
- };
@@ -1,3 +0,0 @@
1
- export const encodeAwsUrlParams = (input: string) => {
2
- return encodeURIComponent(input).replace(/%/g, '$25');
3
- };
@@ -1,95 +0,0 @@
1
- import {MIN_EPHEMERAL_STORAGE_IN_MB} from './constants';
2
- import {pricing} from './price-per-1s';
3
- import type {AwsRegion} from './regions';
4
- import {validateAwsRegion} from './validate-aws-region';
5
- import {validateDiskSizeInMb} from './validate-disk-size-in-mb';
6
- import {validateMemorySize} from './validate-memory-size';
7
-
8
- type Miliseconds =
9
- | {
10
- /**
11
- * @deprecated Typo in property name. Use `durationInMilliseconds` instead.
12
- */
13
- durationInMiliseconds: number;
14
- }
15
- | {
16
- durationInMilliseconds: number;
17
- };
18
-
19
- export type EstimatePriceInput = {
20
- region: AwsRegion;
21
- memorySizeInMb: number;
22
- diskSizeInMb: number;
23
- lambdasInvoked: number;
24
- } & Miliseconds;
25
-
26
- /*
27
- * @description Calculates the AWS costs incurred for AWS Lambda given the region, execution duration and memory size.
28
- * @see [Documentation](https://remotion.dev/docs/lambda/estimateprice)
29
- */
30
- export const estimatePrice = ({
31
- region,
32
- memorySizeInMb,
33
- diskSizeInMb,
34
- lambdasInvoked,
35
- ...other
36
- }: EstimatePriceInput): number => {
37
- validateMemorySize(memorySizeInMb);
38
- validateAwsRegion(region);
39
- validateDiskSizeInMb(diskSizeInMb);
40
-
41
- const durationInMilliseconds =
42
- 'durationInMiliseconds' in other
43
- ? other.durationInMiliseconds
44
- : other.durationInMilliseconds;
45
-
46
- if (typeof durationInMilliseconds !== 'number') {
47
- throw new TypeError(
48
- `Parameter 'durationInMilliseconds' must be a number but got ${typeof durationInMilliseconds}`,
49
- );
50
- }
51
-
52
- if (Number.isNaN(durationInMilliseconds)) {
53
- throw new TypeError(
54
- `Parameter 'durationInMilliseconds' must not be NaN but it is.`,
55
- );
56
- }
57
-
58
- if (!Number.isFinite(durationInMilliseconds)) {
59
- throw new TypeError(
60
- `Parameter 'durationInMilliseconds' must be finite but it is ${durationInMilliseconds}`,
61
- );
62
- }
63
-
64
- if (durationInMilliseconds < 0) {
65
- throw new TypeError(
66
- `Parameter 'durationInMilliseconds' must be over 0 but it is ${durationInMilliseconds}.`,
67
- );
68
- }
69
-
70
- const durationPrice = pricing[region]['Lambda Duration-ARM'].price;
71
-
72
- // In GB-second
73
- const timeCostDollars =
74
- Number(durationPrice) *
75
- ((memorySizeInMb * durationInMilliseconds) / 1000 / 1024);
76
-
77
- const diskSizePrice = pricing[region]['Lambda Storage-Duration-ARM'].price;
78
-
79
- const chargedDiskSize = Math.max(
80
- 0,
81
- diskSizeInMb - MIN_EPHEMERAL_STORAGE_IN_MB,
82
- );
83
- // In GB-second
84
- const diskSizeDollars =
85
- chargedDiskSize *
86
- Number(diskSizePrice) *
87
- (durationInMilliseconds / 1000 / 1024);
88
-
89
- const invocationCost =
90
- Number(pricing[region]['Lambda Requests'].price) * lambdasInvoked;
91
-
92
- return Number(
93
- (timeCostDollars + diskSizeDollars + invocationCost).toFixed(5),
94
- );
95
- };
@@ -1,57 +0,0 @@
1
- import type {Request, Response} from 'express';
2
- import type {NextWebhookArgs} from './app-router-webhook';
3
- import {addHeaders} from './pages-router-webhook';
4
- import {validateWebhookSignature} from './validate-webhook-signature';
5
-
6
- export const expressWebhook = (options: NextWebhookArgs) => {
7
- const {testing, extraHeaders, secret, onSuccess, onTimeout, onError} =
8
- options;
9
- return async (req: Request, res: Response) => {
10
- // add headers to enable testing
11
- if (testing) {
12
- const testingheaders = {
13
- 'Access-Control-Allow-Origin': 'https://www.remotion.dev',
14
- 'Access-Control-Allow-Headers':
15
- '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',
16
- 'Access-Control-Allow-Methods': 'OPTIONS,POST',
17
- };
18
- addHeaders(res, testingheaders);
19
- }
20
-
21
- // add extra headers
22
- addHeaders(res, extraHeaders || {});
23
-
24
- // dont go forward if just testing
25
- if (req.method === 'OPTIONS') {
26
- res.status(200).end();
27
- return;
28
- }
29
-
30
- try {
31
- // validate the webhook signature
32
- validateWebhookSignature({
33
- signatureHeader: req.header('X-Remotion-Signature') as string,
34
- body: req.body,
35
- secret,
36
- });
37
-
38
- // custom logic
39
- const payload = req.body;
40
- if (payload.type === 'success' && onSuccess) {
41
- await onSuccess(payload);
42
- } else if (payload.type === 'error' && onError) {
43
- await onError(payload);
44
- } else if (payload.type === 'timeout' && onTimeout) {
45
- await onTimeout(payload);
46
- }
47
-
48
- // send response
49
- res.status(200).json({success: true});
50
- } catch (err) {
51
- res.status(500).json({
52
- success: false,
53
- error: err instanceof Error ? err.message : String(err),
54
- });
55
- }
56
- };
57
- };
@@ -1,22 +0,0 @@
1
- import {GetCallerIdentityCommand} from '@aws-sdk/client-sts';
2
- import type {GetAccountId} from '@remotion/serverless-client';
3
- import {getStsClient} from './aws-clients';
4
- import type {AwsProvider} from './aws-provider';
5
- import type {AwsRegion} from './regions';
6
- import {validateAwsRegion} from './validate-aws-region';
7
-
8
- export const getAccountIdImplementation: GetAccountId<
9
- AwsProvider
10
- > = async (options: {region: AwsRegion}) => {
11
- validateAwsRegion(options.region);
12
-
13
- const callerIdentity = await getStsClient(options.region, null).send(
14
- new GetCallerIdentityCommand({}),
15
- );
16
-
17
- if (!callerIdentity.Account) {
18
- throw new Error('Cannot get account ID');
19
- }
20
-
21
- return callerIdentity.Account;
22
- };