Skip to content

🎥 Make videos programmatically with React

migrate getAccountId

Jonny Burger9f35e16c3870
diff --git a/packages/lambda/package.json b/packages/lambda/package.json
index 7b845a2342..3e9b2a9237 100644
--- a/packages/lambda/package.json
+++ b/packages/lambda/package.json
@@ -10,8 +10,8 @@
"scripts": {
"formatting": "prettier src --check",
"lint": "eslint src",
- "testlambda": "vitest src/test/integration --run",
- "test": "vitest src/test/unit --run",
+ "testlambda": "bun test src/test/integration",
+ "test": "bun test src/test/unit",
"make": "tsc -d && bun build.ts",
"prepublishOnly": "bun build.ts && bun ensure-version-match.js"
},
diff --git a/packages/lambda/src/api/__mocks__/delete-function.ts b/packages/lambda/src/api/__mocks__/delete-function.ts
deleted file mode 100644
index 1f36693407..0000000000
--- a/packages/lambda/src/api/__mocks__/delete-function.ts
+++ /dev/null
@@ -1,8 +0,0 @@
-import type {deleteFunction as original} from '../delete-function';
-import {deleteMockFunction} from '../mock-functions';
-
-export const deleteFunction: typeof original = ({region, functionName}) => {
- deleteMockFunction(functionName, region);
-
- return Promise.resolve();
-};
diff --git a/packages/lambda/src/api/delete-render.ts b/packages/lambda/src/api/delete-render.ts
index 0b3fa533f4..a846dfde74 100644
--- a/packages/lambda/src/api/delete-render.ts
+++ b/packages/lambda/src/api/delete-render.ts
@@ -8,7 +8,6 @@ import {
import type {AwsProvider} from '../functions/aws-implementation';
import {awsImplementation} from '../functions/aws-implementation';
import type {AwsRegion} from '../regions';
-import {getAccountId} from '../shared/get-account-id';
import {cleanItems} from './clean-items';
export type DeleteRenderInput = {
@@ -25,7 +24,7 @@ export const internalDeleteRender = async (
forcePathStyle: boolean;
},
) => {
- const expectedBucketOwner = await getAccountId({
+ const expectedBucketOwner = await input.providerSpecifics.getAccountId({
region: input.region,
});
const progress = await getOverallProgressFromStorage({
diff --git a/packages/lambda/src/api/delete-site.ts b/packages/lambda/src/api/delete-site.ts
index 0b05a0d5f0..e765684817 100644
--- a/packages/lambda/src/api/delete-site.ts
+++ b/packages/lambda/src/api/delete-site.ts
@@ -3,7 +3,6 @@ import {getSitesKey} from '../defaults';
import type {AwsProvider} from '../functions/aws-implementation';
import {awsImplementation} from '../functions/aws-implementation';
import type {AwsRegion} from '../regions';
-import {getAccountId} from '../shared/get-account-id';
import {cleanItems} from './clean-items';
type MandatoryParameters = {
@@ -37,7 +36,7 @@ export const internalDeleteSite = async ({
}: DeleteSiteInput & {
providerSpecifics: ProviderSpecifics<AwsProvider>;
}): Promise<DeleteSiteOutput> => {
- const accountId = await getAccountId({region});
+ const accountId = await providerSpecifics.getAccountId({region});
let files = await providerSpecifics.listObjects({
bucketName,
diff --git a/packages/lambda/src/api/deploy-function.ts b/packages/lambda/src/api/deploy-function.ts
index 94bfde0984..25b6a26d90 100644
--- a/packages/lambda/src/api/deploy-function.ts
+++ b/packages/lambda/src/api/deploy-function.ts
@@ -1,7 +1,9 @@
import type {LogLevel} from '@remotion/renderer';
import {wrapWithErrorHandling} from '@remotion/renderer/error-handling';
+import type {CloudProvider, ProviderSpecifics} from '@remotion/serverless';
import {VERSION} from 'remotion/version';
import {getFunctions} from '../api/get-functions';
+import {awsImplementation} from '../functions/aws-implementation';
import type {AwsRegion} from '../regions';
import {
DEFAULT_CLOUDWATCH_RETENTION_PERIOD,
@@ -9,7 +11,6 @@ import {
RENDER_FN_PREFIX,
} from '../shared/constants';
import {FUNCTION_ZIP_ARM64} from '../shared/function-zip-path';
-import {getAccountId} from '../shared/get-account-id';
import {
validateRuntimePreference,
type RuntimePreference,
@@ -50,8 +51,11 @@ export type DeployFunctionOutput = {
alreadyExisted: boolean;
};
-export const internalDeployFunction = async (
- params: MandatoryParameters & OptionalParameters,
+export const internalDeployFunction = async <Provider extends CloudProvider>(
+ params: MandatoryParameters &
+ OptionalParameters & {
+ providerSpecifics: ProviderSpecifics<Provider>;
+ },
): Promise<DeployFunctionOutput> => {
validateMemorySize(params.memorySizeInMb);
validateTimeout(params.timeoutInSeconds);
@@ -67,7 +71,9 @@ export const internalDeployFunction = async (
`disk${params.diskSizeInMb}mb`,
`${params.timeoutInSeconds}sec`,
].join('-');
- const accountId = await getAccountId({region: params.region});
+ const accountId = await params.providerSpecifics.getAccountId({
+ region: params.region,
+ });
const fns = await getFunctions({
compatibleOnly: true,
@@ -158,5 +164,6 @@ export const deployFunction = ({
vpcSubnetIds,
vpcSecurityGroupIds,
runtimePreference: runtimePreference ?? 'default',
+ providerSpecifics: awsImplementation,
});
};
diff --git a/packages/lambda/src/api/deploy-site.ts b/packages/lambda/src/api/deploy-site.ts
index db812f860b..32f0342148 100644
--- a/packages/lambda/src/api/deploy-site.ts
+++ b/packages/lambda/src/api/deploy-site.ts
@@ -10,7 +10,6 @@ import {awsImplementation} from '../functions/aws-implementation';
import type {AwsRegion} from '../regions';
import {bundleSite} from '../shared/bundle-site';
import {getSitesKey} from '../shared/constants';
-import {getAccountId} from '../shared/get-account-id';
import {getS3DiffOperations} from '../shared/get-s3-operations';
import {makeS3ServeUrl} from '../shared/make-s3-url';
import {validateAwsRegion} from '../shared/validate-aws-region';
@@ -78,7 +77,7 @@ const mandatoryDeploySite = async ({
validateSiteName(siteName);
validatePrivacy(privacy, false);
- const accountId = await getAccountId({region});
+ const accountId = await providerSpecifics.getAccountId({region});
const bucketExists = await providerSpecifics.bucketExists({
bucketName,
diff --git a/packages/lambda/src/api/download-media.ts b/packages/lambda/src/api/download-media.ts
index 181e701a00..94492bf8ac 100644
--- a/packages/lambda/src/api/download-media.ts
+++ b/packages/lambda/src/api/download-media.ts
@@ -12,7 +12,6 @@ import {awsImplementation} from '../functions/aws-implementation';
import type {LambdaReadFileProgress} from '../functions/helpers/read-with-progress';
import {lambdaDownloadFileWithProgress} from '../functions/helpers/read-with-progress';
import type {AwsRegion} from '../regions';
-import {getAccountId} from '../shared/get-account-id';
export type DownloadMediaInput = {
region: AwsRegion;
@@ -36,7 +35,7 @@ export const internalDownloadMedia = async (
forcePathStyle: boolean;
},
): Promise<DownloadMediaOutput> => {
- const expectedBucketOwner = await getAccountId({
+ const expectedBucketOwner = await input.providerSpecifics.getAccountId({
region: input.region,
});
const overallProgress = await getOverallProgressFromStorage({
diff --git a/packages/lambda/src/api/get-sites.ts b/packages/lambda/src/api/get-sites.ts
index 4db149067c..03aa9f34ae 100644
--- a/packages/lambda/src/api/get-sites.ts
+++ b/packages/lambda/src/api/get-sites.ts
@@ -3,7 +3,6 @@ import type {AwsProvider} from '../functions/aws-implementation';
import {awsImplementation} from '../functions/aws-implementation';
import type {AwsRegion} from '../regions';
import {getSitesKey} from '../shared/constants';
-import {getAccountId} from '../shared/get-account-id';
import {makeS3ServeUrl} from '../shared/make-s3-url';
import type {BucketWithLocation} from './get-buckets';
@@ -51,7 +50,7 @@ export const internalGetSites = async ({
forceBucketName: null,
forcePathStyle,
});
- const accountId = await getAccountId({region});
+ const accountId = await providerSpecifics.getAccountId({region});
const sites: {[key: string]: Site} = {};
diff --git a/packages/lambda/src/cli/commands/functions/deploy.ts b/packages/lambda/src/cli/commands/functions/deploy.ts
index 6d9396cbaf..c90620a18e 100644
--- a/packages/lambda/src/cli/commands/functions/deploy.ts
+++ b/packages/lambda/src/cli/commands/functions/deploy.ts
@@ -2,6 +2,7 @@ import {CliInternals} from '@remotion/cli';
import type {LogLevel} from '@remotion/renderer';
import {VERSION} from 'remotion/version';
import {internalDeployFunction} from '../../../api/deploy-function';
+import {awsImplementation} from '../../../functions/aws-implementation';
import {
DEFAULT_CLOUDWATCH_RETENTION_PERIOD,
DEFAULT_EPHEMERAL_STORAGE_IN_MB,
@@ -99,6 +100,7 @@ VPC Security Group IDs = ${vpcSecurityGroupIds}
vpcSubnetIds,
vpcSecurityGroupIds,
runtimePreference,
+ providerSpecifics: awsImplementation,
});
if (CliInternals.quietFlagProvided()) {
CliInternals.Log.info({indent: false, logLevel}, functionName);
diff --git a/packages/lambda/src/functions/aws-implementation.ts b/packages/lambda/src/functions/aws-implementation.ts
index 862f6517e6..ea1a8aa345 100644
--- a/packages/lambda/src/functions/aws-implementation.ts
+++ b/packages/lambda/src/functions/aws-implementation.ts
@@ -16,6 +16,7 @@ import {callFunctionAsyncImplementation} from '../shared/call-lambda-async';
import {callFunctionWithStreamingImplementation} from '../shared/call-lambda-streaming';
import {callFunctionSyncImplementation} from '../shared/call-lambda-sync';
import {convertToServeUrlImplementation} from '../shared/convert-to-serve-url';
+import {getAccountIdImplementation} from '../shared/get-account-id';
import {
getCloudwatchMethodUrl,
getCloudwatchRendererUrl,
@@ -117,4 +118,5 @@ export const awsImplementation: ProviderSpecifics<AwsProvider> = {
serverStorageProductName: () => 'S3',
getMaxStillInlinePayloadSize: () => 5_000_000,
getMaxNonInlinePayloadSizePerFunction: () => 200_000,
+ getAccountId: getAccountIdImplementation,
};
diff --git a/packages/lambda/src/shared/__mocks__/get-account-id.ts b/packages/lambda/src/shared/__mocks__/get-account-id.ts
deleted file mode 100644
index 226d410428..0000000000
--- a/packages/lambda/src/shared/__mocks__/get-account-id.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import type {getAccountId as original} from '../get-account-id';
-
-export const getAccountId: typeof original = () => {
- const accountId = 'aws:iam::123456789'.match(/aws:iam::([0-9]+)/);
- if (!accountId) {
- throw new Error('Cannot get account ID');
- }
-
- return Promise.resolve(accountId[1]);
-};
diff --git a/packages/lambda/src/shared/get-account-id.ts b/packages/lambda/src/shared/get-account-id.ts
index fea7c106dc..48225bba2a 100644
--- a/packages/lambda/src/shared/get-account-id.ts
+++ b/packages/lambda/src/shared/get-account-id.ts
@@ -1,9 +1,13 @@
import {GetCallerIdentityCommand} from '@aws-sdk/client-sts';
+import type {GetAccountId} from '@remotion/serverless';
+import type {AwsProvider} from '../functions/aws-implementation';
import type {AwsRegion} from '../regions';
import {getStsClient} from './aws-clients';
import {validateAwsRegion} from './validate-aws-region';
-export const getAccountId = async (options: {region: AwsRegion}) => {
+export const getAccountIdImplementation: GetAccountId<
+ AwsProvider
+> = async (options: {region: AwsRegion}) => {
validateAwsRegion(options.region);
const callerIdentity = await getStsClient(options.region).send(
diff --git a/packages/lambda/src/test/integration/deploy-function.test.ts b/packages/lambda/src/test/integration/deploy-function.test.ts
index 21cdaadc17..197325ae97 100644
--- a/packages/lambda/src/test/integration/deploy-function.test.ts
+++ b/packages/lambda/src/test/integration/deploy-function.test.ts
@@ -1,24 +1,35 @@
import {VERSION} from 'remotion/version';
import {expect, test} from 'vitest';
-import {deleteFunction} from '../../api/delete-function';
-import {deployFunction} from '../../api/deploy-function';
+import {internalDeployFunction} from '../../api/deploy-function';
import {getFunctions} from '../../api/get-functions';
import {
cleanFnStore,
+ deleteMockFunction,
markFunctionAsIncompatible,
} from '../../api/mock-functions';
import {DEFAULT_EPHEMERAL_STORAGE_IN_MB} from '../../shared/constants';
import {LAMBDA_VERSION_STRING} from '../../shared/lambda-version-string';
+import {mockImplementation} from '../mock-implementation';
const expectedFunctionName = (memory: number, timeout: number, disk: number) =>
`remotion-render-${LAMBDA_VERSION_STRING}-mem${memory}mb-disk${disk}mb-${timeout}sec`;
test('Should be able to deploy function', async () => {
- const {functionName} = await deployFunction({
+ const {functionName} = await internalDeployFunction({
memorySizeInMb: 2048,
region: 'us-east-1',
timeoutInSeconds: 120,
createCloudWatchLogGroup: true,
+ customRoleArn: undefined,
+ diskSizeInMb: 10240,
+ enableLambdaInsights: true,
+ indent: false,
+ logLevel: 'info',
+ providerSpecifics: mockImplementation,
+ runtimePreference: 'default',
+ vpcSecurityGroupIds: undefined,
+ vpcSubnetIds: undefined,
+ cloudWatchLogRetentionPeriodInDays: undefined,
});
expect(functionName).toBe(
expectedFunctionName(2048, 120, DEFAULT_EPHEMERAL_STORAGE_IN_MB),
@@ -28,11 +39,21 @@ test('Should be able to deploy function', async () => {
test('Should be able to get the function afterwards', async () => {
cleanFnStore();
- const {functionName} = await deployFunction({
+ const {functionName} = await internalDeployFunction({
memorySizeInMb: 2048,
region: 'us-east-1',
timeoutInSeconds: 120,
createCloudWatchLogGroup: true,
+ customRoleArn: undefined,
+ diskSizeInMb: 10240,
+ enableLambdaInsights: true,
+ indent: false,
+ logLevel: 'info',
+ providerSpecifics: mockImplementation,
+ runtimePreference: 'default',
+ vpcSecurityGroupIds: undefined,
+ vpcSubnetIds: undefined,
+ cloudWatchLogRetentionPeriodInDays: undefined,
});
expect(functionName).toBe(
expectedFunctionName(2048, 120, DEFAULT_EPHEMERAL_STORAGE_IN_MB),
@@ -65,23 +86,29 @@ test('Should be able to get the function afterwards', async () => {
test('Should be able to delete the function', async () => {
cleanFnStore();
- const {functionName} = await deployFunction({
+ const {functionName} = await internalDeployFunction({
memorySizeInMb: 2048,
region: 'us-east-1',
timeoutInSeconds: 120,
createCloudWatchLogGroup: true,
+ customRoleArn: undefined,
+ diskSizeInMb: 10240,
+ enableLambdaInsights: true,
+ indent: false,
+ logLevel: 'info',
+ providerSpecifics: mockImplementation,
+ runtimePreference: 'default',
+ vpcSecurityGroupIds: undefined,
+ vpcSubnetIds: undefined,
+ cloudWatchLogRetentionPeriodInDays: undefined,
});
expect(functionName).toBe(
expectedFunctionName(2048, 120, DEFAULT_EPHEMERAL_STORAGE_IN_MB),
);
- await deleteFunction({
- region: 'us-east-1',
- functionName: expectedFunctionName(
- 2048,
- 120,
- DEFAULT_EPHEMERAL_STORAGE_IN_MB,
- ),
- });
+ deleteMockFunction(
+ expectedFunctionName(2048, 120, DEFAULT_EPHEMERAL_STORAGE_IN_MB),
+ 'us-east-1',
+ );
const fns = await getFunctions({
region: 'us-east-1',
compatibleOnly: true,
@@ -92,11 +119,21 @@ test('Should be able to delete the function', async () => {
test('Should be able to get the function afterwards', async () => {
cleanFnStore();
- const {functionName} = await deployFunction({
+ const {functionName} = await internalDeployFunction({
memorySizeInMb: 2048,
region: 'us-east-1',
timeoutInSeconds: 120,
createCloudWatchLogGroup: true,
+ customRoleArn: undefined,
+ diskSizeInMb: 10240,
+ enableLambdaInsights: true,
+ indent: false,
+ logLevel: 'info',
+ providerSpecifics: mockImplementation,
+ runtimePreference: 'default',
+ vpcSecurityGroupIds: undefined,
+ vpcSubnetIds: undefined,
+ cloudWatchLogRetentionPeriodInDays: undefined,
});
expect(functionName).toBe(
expectedFunctionName(2048, 120, DEFAULT_EPHEMERAL_STORAGE_IN_MB),
diff --git a/packages/lambda/src/test/integration/deploy-site.test.ts b/packages/lambda/src/test/integration/deploy-site.test.ts
index 44f93a95d6..906c3510a9 100644
--- a/packages/lambda/src/test/integration/deploy-site.test.ts
+++ b/packages/lambda/src/test/integration/deploy-site.test.ts
@@ -3,10 +3,11 @@ import {expect, test} from 'vitest';
import {internalDeleteSite} from '../../api/delete-site';
import {internalDeploySite} from '../../api/deploy-site';
import {getDirFiles} from '../../api/upload-dir';
+import {awsImplementation} from '../../functions/aws-implementation';
import {mockImplementation} from '../mock-implementation';
test('Should throw on wrong prefix', async () => {
- await expect(() =>
+ await expect(
internalDeploySite({
bucketName: 'wrongprefix',
entryPoint: 'first',
@@ -25,7 +26,7 @@ test('Should throw on wrong prefix', async () => {
});
test('Should throw if invalid region was passed', () => {
- expect(() =>
+ expect(
internalDeploySite({
bucketName: 'remotionlambda-testing',
entryPoint: 'first',
@@ -33,7 +34,7 @@ test('Should throw if invalid region was passed', () => {
region: 'ap-northeast-9',
siteName: 'testing',
gitSource: null,
- providerSpecifics: mockImplementation,
+ providerSpecifics: awsImplementation,
indent: false,
logLevel: 'info',
options: {},
@@ -44,7 +45,7 @@ test('Should throw if invalid region was passed', () => {
});
test("Should throw if bucket doesn't exist", () => {
- expect(() =>
+ expect(
internalDeploySite({
bucketName: 'remotionlambda-non-existed',
entryPoint: 'first',
diff --git a/packages/lambda/src/test/mock-implementation.ts b/packages/lambda/src/test/mock-implementation.ts
index a0eb66f853..d3408033be 100644
--- a/packages/lambda/src/test/mock-implementation.ts
+++ b/packages/lambda/src/test/mock-implementation.ts
@@ -40,6 +40,8 @@ export const getBrowserInstance: GetBrowserInstance = async () => {
};
export const mockImplementation: ProviderSpecifics<AwsProvider> = {
+ getAccountId: () =>
+ Promise.resolve('aws:iam::123456789'.match(/aws:iam::([0-9]+)/)?.[1]!),
getMaxNonInlinePayloadSizePerFunction: () => 200_000,
getMaxStillInlinePayloadSize() {
return 5_000_000;
diff --git a/packages/lambda/vitest.config.mts b/packages/lambda/vitest.config.mts
deleted file mode 100644
index 1727d3f97f..0000000000
--- a/packages/lambda/vitest.config.mts
+++ /dev/null
@@ -1,11 +0,0 @@
-import {defineConfig} from 'vitest/config';
-
-export default defineConfig({
- test: {
- setupFiles: ['./src/test/setup.ts'],
- maxConcurrency: 1,
- testTimeout: 90000,
- maxThreads: 1,
- minThreads: 1,
- },
-});
diff --git a/packages/serverless/src/provider-implementation.ts b/packages/serverless/src/provider-implementation.ts
index 2e16553db3..b5708f1183 100644
--- a/packages/serverless/src/provider-implementation.ts
+++ b/packages/serverless/src/provider-implementation.ts
@@ -233,6 +233,10 @@ export type GenerateRenderId = (options: {
randomHashFn: () => string;
}) => string;
+export type GetAccountId<Provider extends CloudProvider> = (options: {
+ region: Provider['region'];
+}) => Promise<string>;
+
export type ServerProviderSpecifics = {
getBrowserInstance: GetBrowserInstance;
forgetBrowserEventLoop: ForgetBrowserEventLoop;
@@ -273,4 +277,5 @@ export type ProviderSpecifics<Provider extends CloudProvider> = {
serverStorageProductName: () => string;
getMaxStillInlinePayloadSize: () => number;
getMaxNonInlinePayloadSizePerFunction: () => number;
+ getAccountId: GetAccountId<Provider>;
};