Skip to content

🎥 Make videos programmatically with React

customCredentials + warn

Jonny Burgere08224d59d2b
diff --git a/packages/lambda/src/api/get-or-create-bucket.ts b/packages/lambda/src/api/get-or-create-bucket.ts
index 0b32881315..111ab61104 100644
--- a/packages/lambda/src/api/get-or-create-bucket.ts
+++ b/packages/lambda/src/api/get-or-create-bucket.ts
@@ -1,4 +1,5 @@
import type {AwsRegion} from '../pricing/aws-regions';
+import type {CustomCredentials} from '../shared/aws-clients';
import {REMOTION_BUCKET_PREFIX} from '../shared/constants';
import {applyLifeCyleOperation} from '../shared/lifecycle-rules';
import {makeBucketName} from '../shared/validate-bucketname';
@@ -8,11 +9,13 @@ import {getRemotionS3Buckets} from './get-buckets';
type GetOrCreateBucketInputInner = {
region: AwsRegion;
enableFolderExpiry: boolean | null;
+ customCredentials: CustomCredentials | null;
};
export type GetOrCreateBucketInput = {
region: AwsRegion;
enableFolderExpiry?: boolean;
+ customCredentials?: CustomCredentials;
};
export type GetOrCreateBucketOutput = {
@@ -42,6 +45,7 @@ export const internalGetOrCreateBucket = async (
enableFolderExpiry: enableFolderExpiry ?? null,
bucketName: existingBucketName,
region,
+ customCredentials: params.customCredentials,
});
return {bucketName: remotionBuckets[0].name, alreadyExisted: true};
@@ -59,6 +63,7 @@ export const internalGetOrCreateBucket = async (
enableFolderExpiry: enableFolderExpiry ?? null,
bucketName,
region,
+ customCredentials: params.customCredentials,
});
return {bucketName, alreadyExisted: false};
@@ -74,5 +79,6 @@ export const getOrCreateBucket = (options: GetOrCreateBucketInput) => {
return internalGetOrCreateBucket({
region: options.region,
enableFolderExpiry: options.enableFolderExpiry ?? null,
+ customCredentials: options.customCredentials ?? null,
});
};
diff --git a/packages/lambda/src/api/iam-validation/user-permissions.ts b/packages/lambda/src/api/iam-validation/user-permissions.ts
index 046d821e75..bad9a33351 100644
--- a/packages/lambda/src/api/iam-validation/user-permissions.ts
+++ b/packages/lambda/src/api/iam-validation/user-permissions.ts
@@ -52,6 +52,7 @@ export const requiredPermissions: {
s3.DeleteBucket,
s3.PutBucketOwnershipControls,
s3.PutBucketPublicAccessBlock,
+ s3.PutLifecycleConfiguration,
],
resource: [`arn:aws:s3:::${REMOTION_BUCKET_PREFIX}*`],
},
diff --git a/packages/lambda/src/cli/commands/sites/create.ts b/packages/lambda/src/cli/commands/sites/create.ts
index 752318fa37..67405bd839 100644
--- a/packages/lambda/src/cli/commands/sites/create.ts
+++ b/packages/lambda/src/cli/commands/sites/create.ts
@@ -96,6 +96,7 @@ export const sitesCreateSubcommand = async (
await internalGetOrCreateBucket({
region: getAwsRegion(),
enableFolderExpiry: enableFolderExpiry ?? null,
+ customCredentials: null,
})
).bucketName;
diff --git a/packages/lambda/src/cli/commands/sites/rm.ts b/packages/lambda/src/cli/commands/sites/rm.ts
index ffa0914a6d..d595097e34 100644
--- a/packages/lambda/src/cli/commands/sites/rm.ts
+++ b/packages/lambda/src/cli/commands/sites/rm.ts
@@ -34,6 +34,7 @@ export const sitesRmSubcommand = async (args: string[]) => {
await internalGetOrCreateBucket({
region,
enableFolderExpiry: parsedLambdaCli['enable-folder-expiry'] ?? null,
+ customCredentials: null,
})
).bucketName;
diff --git a/packages/lambda/src/cli/commands/sites/rmall.ts b/packages/lambda/src/cli/commands/sites/rmall.ts
index e85644d79f..19eaedfebf 100644
--- a/packages/lambda/src/cli/commands/sites/rmall.ts
+++ b/packages/lambda/src/cli/commands/sites/rmall.ts
@@ -21,6 +21,7 @@ export const sitesRmallSubcommand = async () => {
await internalGetOrCreateBucket({
region,
enableFolderExpiry: parsedLambdaCli['enable-folder-expiry'] ?? null,
+ customCredentials: null,
})
).bucketName;
diff --git a/packages/lambda/src/functions/compositions.ts b/packages/lambda/src/functions/compositions.ts
index 5aaa10ebb0..692dff05a9 100644
--- a/packages/lambda/src/functions/compositions.ts
+++ b/packages/lambda/src/functions/compositions.ts
@@ -39,6 +39,7 @@ export const compositionsHandler = async (
internalGetOrCreateBucket({
region,
enableFolderExpiry: null,
+ customCredentials: null,
}).then((b) => b.bucketName),
getBrowserInstance(
lambdaParams.logLevel,
diff --git a/packages/lambda/src/functions/start.ts b/packages/lambda/src/functions/start.ts
index 3d3d824aa6..c5b80c1ffd 100644
--- a/packages/lambda/src/functions/start.ts
+++ b/packages/lambda/src/functions/start.ts
@@ -37,6 +37,7 @@ export const startHandler = async (params: LambdaPayload, options: Options) => {
await internalGetOrCreateBucket({
region: getCurrentRegionInFunction(),
enableFolderExpiry: null,
+ customCredentials: null,
})
).bucketName;
const realServeUrl = convertToServeUrl({
diff --git a/packages/lambda/src/functions/still.ts b/packages/lambda/src/functions/still.ts
index 9a99d2f6b3..2e3ba119ad 100644
--- a/packages/lambda/src/functions/still.ts
+++ b/packages/lambda/src/functions/still.ts
@@ -80,6 +80,7 @@ const innerStillHandler = async ({
internalGetOrCreateBucket({
region: getCurrentRegionInFunction(),
enableFolderExpiry: null,
+ customCredentials: null,
}).then((b) => b.bucketName),
getBrowserInstance(
lambdaParams.logLevel,
@@ -306,6 +307,7 @@ export const stillHandler = async (
await internalGetOrCreateBucket({
region: getCurrentRegionInFunction(),
enableFolderExpiry: null,
+ customCredentials: null,
})
).bucketName;
diff --git a/packages/lambda/src/shared/compress-props.ts b/packages/lambda/src/shared/compress-props.ts
index fa9783d9e9..e827ded78d 100644
--- a/packages/lambda/src/shared/compress-props.ts
+++ b/packages/lambda/src/shared/compress-props.ts
@@ -74,6 +74,7 @@ export const compressInputProps = async ({
await internalGetOrCreateBucket({
region,
enableFolderExpiry: null,
+ customCredentials: null,
})
).bucketName;
diff --git a/packages/lambda/src/shared/lifecycle-rules.ts b/packages/lambda/src/shared/lifecycle-rules.ts
index c6dde21e98..e57baa0196 100644
--- a/packages/lambda/src/shared/lifecycle-rules.ts
+++ b/packages/lambda/src/shared/lifecycle-rules.ts
@@ -8,14 +8,17 @@ import {
deleteLifeCycleInput,
} from '../functions/helpers/apply-lifecyle';
import {getLifeCycleRules} from '../functions/helpers/lifecycle';
+import type {CustomCredentials} from './aws-clients';
import {getS3Client} from './aws-clients';
const createLCRules = async ({
bucketName,
region,
+ customCredentials,
}: {
bucketName: string;
region: AwsRegion;
+ customCredentials: CustomCredentials | null;
}) => {
const lcRules = getLifeCycleRules();
// create the lifecyle rules
@@ -26,40 +29,64 @@ const createLCRules = async ({
const createCommand = new PutBucketLifecycleConfigurationCommand(
createCommandInput,
);
- await getS3Client(region, null).send(createCommand);
+ try {
+ await getS3Client(region, customCredentials).send(createCommand);
+ } catch (err) {
+ if ((err as Error).message.includes('AccessDenied')) {
+ throw new Error(
+ `You don't have the required permissions to create lifecycle rules on the bucket "${bucketName}". Ensure that your user has the "s3:PutLifecycleConfiguration" permission.`,
+ );
+ }
+
+ console.log({err});
+ }
};
const deleteLCRules = async ({
bucketName,
region,
+ customCredentials,
}: {
bucketName: string;
region: AwsRegion;
+ customCredentials: CustomCredentials | null;
}) => {
const deleteCommandInput = deleteLifeCycleInput({
bucketName,
});
- await getS3Client(region, null).send(
- new DeleteBucketLifecycleCommand(deleteCommandInput),
- );
+ try {
+ await getS3Client(region, customCredentials).send(
+ new DeleteBucketLifecycleCommand(deleteCommandInput),
+ );
+ } catch (err) {
+ if ((err as Error).message.includes('AccessDenied')) {
+ throw new Error(
+ `You don't have the required permissions to delete lifecycle rules on the bucket "${bucketName}". Ensure that your user has the "s3:PutLifecycleConfiguration" permission.`,
+ );
+ }
+
+ console.log({err});
+ }
};
export const applyLifeCyleOperation = async ({
enableFolderExpiry,
bucketName,
region,
+ customCredentials,
}: {
enableFolderExpiry: boolean | null;
bucketName: string;
region: AwsRegion;
+ customCredentials: CustomCredentials | null;
}) => {
if (enableFolderExpiry === null) {
return;
}
if (enableFolderExpiry === true) {
- await createLCRules({bucketName, region});
+ await createLCRules({bucketName, region, customCredentials});
} else {
- await deleteLCRules({bucketName, region});
+ await deleteLCRules({bucketName, region, customCredentials});
}
};