Skip to main content

getAwsClient()

这个 API 提供了对 Remotion 底层使用的 AWS SDK 的完全访问权限。你可以使用它以 Remotion 没有提供函数的方式与 AWS 基础设施进行交互。

🌐 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

// Import from "@remotion/lambda" instead before Remotion v4.0.60
import {getAwsClient, getRenderProgress} from '@remotion/lambda/client';
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;
};

示例:为存储桶启用 CORS

🌐 Example: Enable CORS for a bucket

// Import from "@remotion/lambda" instead before Remotion v4.0.60
import {getAwsClient} from '@remotion/lambda/client';

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

Remotion Lambda 的支持区域之一,应为此区域实例化客户端。

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

service

lambdacloudwatchiamservicequotass3sts之一。

🌐 One of lambda, cloudwatch, iam, servicequotas, s3 or sts.

customCredentials?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:

type CustomCredentials = {
  endpoint: string;
  accessKeyId: string | null;
  secretAccessKey: string | null;
  region?: string;
  forcePathStyle?: boolean;
};

forcePathStyle?v4.0.202

forcePathStyle 传递给 AWS S3 客户端。如果你不知道这是什么,你很可能用不到它。

🌐 Passes forcePathStyle to the AWS S3 client. If you don't know what this is, you probably don't need it.

返回值

🌐 Return value

具有两个属性的对象:

🌐 An object with two properties:

client

一个使用你传入的区域和你在调用函数时设置的凭证实例化的 AWS SDK 客户端。

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

sdk

你指定的服务的完整 SDK JavaScript 模块。

🌐 The full SDK JavaScript module for the service you specified.

note

你不需要从 SDK 创建新的客户端,而应该重用同样由 Remotion 返回并使用的 client,以节省内存。

另请参阅

🌐 See also