Skip to content

🎥 Make videos programmatically with React

explicit account id

Jonny Burgerda6215e49147
diff --git a/packages/lambda/src/api/delete-site.ts b/packages/lambda/src/api/delete-site.ts
index 4bee86fe2e..8ce87b2ae3 100644
--- a/packages/lambda/src/api/delete-site.ts
+++ b/packages/lambda/src/api/delete-site.ts
@@ -1,6 +1,7 @@
import {AwsRegion} from '..';
import {getSitesKey} from '../defaults';
import {lambdaLs} from '../functions/helpers/io';
+import {getAccountId} from '../shared/get-account-id';
import {cleanItems} from './clean-items';
type DeleteSiteReturnData = {
@@ -19,11 +20,13 @@ export const deleteSite = async ({
region: AwsRegion;
onAfterItemDeleted?: (data: {bucketName: string; itemName: string}) => void;
}): Promise<DeleteSiteReturnData> => {
+ const accountId = await getAccountId({region});
+
let files = await lambdaLs({
bucketName,
prefix: getSitesKey(siteName),
region,
- expectedBucketOwner: null,
+ expectedBucketOwner: accountId,
});
if (files.length === 0) {
@@ -49,7 +52,7 @@ export const deleteSite = async ({
bucketName,
prefix: getSitesKey(siteName),
region,
- expectedBucketOwner: null,
+ expectedBucketOwner: accountId,
});
}
diff --git a/packages/lambda/src/api/deploy-site.ts b/packages/lambda/src/api/deploy-site.ts
index 8c411dc689..ea589b8045 100644
--- a/packages/lambda/src/api/deploy-site.ts
+++ b/packages/lambda/src/api/deploy-site.ts
@@ -3,6 +3,7 @@ import {deleteSite} from '../api/delete-site';
import {AwsRegion} from '../pricing/aws-regions';
import {bundleSite} from '../shared/bundle-site';
import {getSitesKey, REMOTION_BUCKET_PREFIX} from '../shared/constants';
+import {getAccountId} from '../shared/get-account-id';
import {makeS3Url} from '../shared/make-s3-url';
import {randomHash} from '../shared/random-hash';
import {validateAwsRegion} from '../shared/validate-aws-region';
@@ -62,8 +63,7 @@ export const deploySite = async ({
const bucketExists = await bucketExistsInRegion({
bucketName,
region,
- // TODO: Pass actual bucket owner
- expectedBucketOwner: null,
+ expectedBucketOwner: await getAccountId({region}),
});
if (!bucketExists) {
throw new Error(`No bucket with the name ${bucketName} exists`);
diff --git a/packages/lambda/src/api/get-sites.ts b/packages/lambda/src/api/get-sites.ts
index 8b0fa0592c..24c7f9288c 100644
--- a/packages/lambda/src/api/get-sites.ts
+++ b/packages/lambda/src/api/get-sites.ts
@@ -1,6 +1,7 @@
import {lambdaLs} from '../functions/helpers/io';
import {AwsRegion} from '../pricing/aws-regions';
import {getSitesKey} from '../shared/constants';
+import {getAccountId} from '../shared/get-account-id';
import {getRemotionS3Buckets} from './get-buckets';
type Site = {
@@ -13,6 +14,7 @@ type Site = {
// TODO: Add JSDoc comments
export const getSites = async ({region}: {region: AwsRegion}) => {
const {remotionBuckets} = await getRemotionS3Buckets(region);
+ const accountId = await getAccountId({region});
const sites: {[key: string]: Site} = {};
@@ -21,7 +23,7 @@ export const getSites = async ({region}: {region: AwsRegion}) => {
bucketName: bucket.Name as string,
prefix: getSitesKey(''),
region,
- expectedBucketOwner: null,
+ expectedBucketOwner: accountId,
});
for (const file of ls) {
diff --git a/packages/lambda/src/cli/cleanup.ts b/packages/lambda/src/cli/cleanup.ts
index af62a61aff..df218741bb 100644
--- a/packages/lambda/src/cli/cleanup.ts
+++ b/packages/lambda/src/cli/cleanup.ts
@@ -6,6 +6,7 @@ import {cleanUpBuckets} from '../cleanup/s3-buckets';
import {AwsRegion} from '../pricing/aws-regions';
import {chunk} from '../shared/chunk';
import {BINARY_NAME} from '../shared/constants';
+import {getAccountId} from '../shared/get-account-id';
import {getAwsRegion} from './get-aws-region';
import {Log} from './log';
@@ -33,7 +34,7 @@ const cleanupBucketsCommand = async (region: AwsRegion) => {
},
onAfterBucketDeleted: (bucketName: string) =>
Log.info(CliInternals.chalk.blue(`Deleted bucket ${bucketName}.`)),
- expectedBucketOwner: null,
+ expectedBucketOwner: await getAccountId({region}),
});
Log.info('All Remotion-related buckets deleted.');
};
diff --git a/packages/lambda/src/run.ts b/packages/lambda/src/run.ts
deleted file mode 100644
index a98bdc12b8..0000000000
--- a/packages/lambda/src/run.ts
+++ /dev/null
@@ -1,117 +0,0 @@
-import {CliInternals} from '@remotion/cli';
-import path from 'path';
-import {deployFunction} from './api/deploy-function';
-import {deploySite} from './api/deploy-site';
-import {getRemotionS3Buckets} from './api/get-buckets';
-import {getFunctions} from './api/get-functions';
-import {getOrCreateBucket} from './api/get-or-create-bucket';
-import {getRenderProgress} from './api/get-render-progress';
-import {cleanupLambdas} from './cleanup/cleanup-lambdas';
-import {getAwsRegion} from './cli/get-aws-region';
-import {Log} from './cli/log';
-import {lambdaLs} from './functions/helpers/io';
-import {AwsRegion} from './pricing/aws-regions';
-import {callLambda} from './shared/call-lambda';
-import {
- getSitesKey,
- LambdaRoutines,
- REMOTION_BUCKET_PREFIX,
-} from './shared/constants';
-import {makeS3Url} from './shared/make-s3-url';
-import {sleep} from './shared/sleep';
-
-const DEPLOY = false;
-
-const getFnName = async (options: {
- region: AwsRegion;
-}): Promise<{
- functionName: string;
- bucketUrl: string;
- compositionName: string;
-}> => {
- const {bucketName} = await getOrCreateBucket({region: getAwsRegion()});
- if (DEPLOY) {
- await cleanupLambdas({region: options.region});
- // await cleanUpBuckets({s3client: s3Client});
-
- const {functionName} = await deployFunction({
- region: getAwsRegion(),
- timeoutInSeconds: 120,
- memorySizeInMb: 2048,
- });
-
- const {url} = await deploySite({
- entryPoint: path.join(__dirname, '..', 'remotion-project', 'index.ts'),
- bucketName,
- region: getAwsRegion(),
- });
-
- return {functionName, bucketUrl: url, compositionName: 'my-video'};
- }
-
- const lambdas = await getFunctions({
- region: options.region,
- compatibleOnly: true,
- });
- const {remotionBuckets} = await getRemotionS3Buckets(options.region);
- const websiteBuckets = remotionBuckets.filter((b) =>
- (b.Name as string).startsWith(REMOTION_BUCKET_PREFIX)
- );
- const prefix = getSitesKey('');
- const firstBucket = await lambdaLs({
- bucketName: websiteBuckets[0].Name as string,
- prefix,
- region: getAwsRegion(),
- expectedBucketOwner: null,
- });
- const firstSite = firstBucket.find(() => true);
- return {
- functionName: lambdas[0].functionName as string,
- bucketUrl: makeS3Url({
- bucketName: websiteBuckets[0].Name as string,
- subFolder: firstSite?.Key?.match(/(sites\/.*)\//)?.[1] as string,
- region: getAwsRegion(),
- }),
- compositionName: 'Main',
- };
-};
-
-CliInternals.xns(async () => {
- const {functionName, bucketUrl, compositionName} = await getFnName({
- region: getAwsRegion(),
- });
- const res = await callLambda({
- functionName,
- type: LambdaRoutines.start,
- payload: {
- framesPerLambda: 20,
- composition: compositionName,
- serveUrl: bucketUrl,
- inputProps: {},
- codec: 'h264-mkv',
- imageFormat: 'jpeg',
- crf: undefined,
- envVariables: {},
- pixelFormat: undefined,
- proResProfile: undefined,
- quality: undefined,
- maxRetries: 3,
- },
- region: 'eu-central-1',
- });
- Log.info(bucketUrl);
- for (let i = 0; i < 3000; i++) {
- await sleep(1000);
- const status = await getRenderProgress({
- functionName,
- bucketName: res.bucketName,
- renderId: res.renderId,
- region: getAwsRegion(),
- });
- Log.info(status);
- if (status.done) {
- Log.info('Done! ' + res.bucketName);
- break;
- }
- }
-});