getAwsClient()
此 API 公开了 Remotion 底层使用的 AWS SDK 的完整访问权限。您可以使用它以一种 Remotion 未提供函数的方式与您的 AWS 基础设施进行交互。
示例:获取用于渲染的缓冲区
tsx
// Import from "@remotion/lambda" instead before Remotion v4.0.60import { 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 renderedreturn;}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 from "@remotion/lambda" instead before Remotion v4.0.60import { 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 renderedreturn;}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
tsx
// Import from "@remotion/lambda" instead before Remotion v4.0.60import { 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: ["*"],},],},}),);
tsx
// Import from "@remotion/lambda" instead before Remotion v4.0.60import { 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: ["*"],},],},}),);
参数
一个带有两个必需参数的对象:
region
Remotion Lambda 支持的受支持区域之一,应该为其实例化客户端。
service
其中之一:lambda
、cloudwatch
、iam
、servicequotas
、s3
或 sts
。
customCredentials?
v3.2.23
允许您连接到另一个云提供商,如果您将输出呈现到不同的云上,则很有用。该值必须满足以下类型:
ts
type CustomCredentials = {endpoint: string;accessKeyId: string | null;secretAccessKey: string | null;};
ts
type CustomCredentials = {endpoint: string;accessKeyId: string | null;secretAccessKey: string | null;};
forcePathStyle?
v4.0.202
将 forcePathStyle
传递给 AWS S3 客户端。如果您不知道这是什么,您可能不需要它。
返回值
一个带有两个属性的对象:
client
使用您传递的区域和在调用函数时设置的凭据实例化的 AWS SDK 客户端。
- 对于
s3
:S3Client 的实例 - 对于
iam
:IAMClient 的实例 - 对于
cloudwatch
:CloudWatchLogsClient 的实例 - 对于
servicequotas
:ServiceQuotasClient 的实例 - 对于
lambda
:LambdaClient 的实例
SDK
为您指定的服务提供完整的 SDK JavaScript 模块。
- 对于
s3
:@aws-sdk/client-s3
包 - 对于
iam
:@aws-sdk/client-iam
包 - 对于
cloudwatch
:@aws-sdk/client-cloudwatch-logs
包 - 对于
servicequotas
:@aws-sdk/client-service-quotas
包 - 对于
lambda
:@aws-sdk/client-lambda
包
note
您无需从 SDK 创建新的客户端,而应该重用由 Remotion 返回并被使用的 client
,以节省内存。