Skip to main content

getAwsClient()

This API exposes full access to the AWS SDK that Remotion uses under the hood. You can use it to interact with your AWS infrastructure in ways that Remotion doesn't provide a function for.

Example: Getting a buffer for a render

tsx
import { getAwsClient, getRenderProgress } from "@remotion/lambda";
import { Readable } from "stream";
const bucketName = "remotionlambda-d9mafgx";
const getFileAsBuffer = async () => {
const progress = await getRenderProgress({
renderId: "d7nlc2y",
bucketName: "remotionlambda-d9mafgx",
functionName: "remotion-render-la8ffw",
region: "us-east-1",
});
if (!progress.outKey) {
// Video not yet rendered
return;
}
const { client, sdk } = getAwsClient({ region: "us-east-1", service: "s3" });
const data = client.send(
new sdk.GetObjectCommand({
Bucket: bucketName,
Key: progress.outKey,
})
);
return data.Body as Readable;
};
tsx
import { getAwsClient, getRenderProgress } from "@remotion/lambda";
import { Readable } from "stream";
const bucketName = "remotionlambda-d9mafgx";
const getFileAsBuffer = async () => {
const progress = await getRenderProgress({
renderId: "d7nlc2y",
bucketName: "remotionlambda-d9mafgx",
functionName: "remotion-render-la8ffw",
region: "us-east-1",
});
if (!progress.outKey) {
// Video not yet rendered
return;
}
const { client, sdk } = getAwsClient({ region: "us-east-1", service: "s3" });
const data = client.send(
new sdk.GetObjectCommand({
Bucket: bucketName,
Key: progress.outKey,
})
);
return data.Body as Readable;
};

Example: Enable CORS for a bucket

tsx
import { getAwsClient } from "@remotion/lambda";
const { client, sdk } = getAwsClient({ region: "us-east-1", service: "s3" });
client.send(
new sdk.PutBucketCorsCommand({
Bucket: "[bucket-name]",
CORSConfiguration: {
CORSRules: [
{
AllowedMethods: ["GET", "HEAD"],
AllowedHeaders: ["*"],
AllowedOrigins: ["*"],
},
],
},
})
);
tsx
import { getAwsClient } from "@remotion/lambda";
const { client, sdk } = getAwsClient({ region: "us-east-1", service: "s3" });
client.send(
new sdk.PutBucketCorsCommand({
Bucket: "[bucket-name]",
CORSConfiguration: {
CORSRules: [
{
AllowedMethods: ["GET", "HEAD"],
AllowedHeaders: ["*"],
AllowedOrigins: ["*"],
},
],
},
})
);

Arguments

An object with two mandatory parameters:

region

One of the supported regions of Remotion Lambda, for which the client should be instantiated.

service

One of lambda, cloudwatch, iam, servicequotas and s3.

customCredentials

available from v3.2.23

Allows you to connect to another cloud provider, useful if you render your output to a different cloud. The value must satisfy the following type:

ts
type CustomCredentials = {
endpoint: string;
accessKeyId: string | null;
secretAccessKey: string | null;
};
ts
type CustomCredentials = {
endpoint: string;
accessKeyId: string | null;
secretAccessKey: string | null;
};

Return value

An object with two properties:

client

An AWS SDK client instantiated with the region you passed and the credentials you had set at the time of calling the function.

sdk

The full SDK JavaScript module for the service you specified.

note

You don't need to create a new client from the SDK and should instead reuse the client that is also returned and being used by Remotion, in order to save memory.

See also