🎥 Make videos programmatically with React
replace with getAwsClients
Jonny Burger0f57fa180e2d
diff --git a/packages/docs/docs/lambda/gets3object.md b/packages/docs/docs/lambda/gets3object.mddeleted file mode 100644index c05a214dd7..0000000000--- a/packages/docs/docs/lambda/gets3object.md+++ /dev/null@@ -1,43 +0,0 @@-----id: gets3object-title: getS3Object()-slug: /lambda/gets3object------Retrieves an object stored in Remotion's S3 bucket.--## Example--```ts twoslash-import fs from "fs";-import { getS3Object } from "@remotion/lambda";--const data = await getS3Object({- region: 'us-east-1',- bucketName: 'remotionlambda-fz1zu45ztk',- objectKey: 'assets/sample.jpeg',-});--const file = fs.createWriteStream('sample.jpeg');-data.pipe(file);-```--## Arguments--An object with the following properties:--### `region`--The AWS region in which the bucket resides.--### `bucketName`--The bucket where the asset exists. The bucket must have been created by Remotion Lambda.--### `objectKey`--They key that uniquely identifies the object stored in the bucket.--## See also--- [`presignUrl()`](/docs/lambda/presignurl)diff --git a/packages/docs/docs/lambda/presignurl.md b/packages/docs/docs/lambda/presignurl.mdindex b0d1ffb0ca..72c2397473 100644--- a/packages/docs/docs/lambda/presignurl.md+++ b/packages/docs/docs/lambda/presignurl.md@@ -48,5 +48,3 @@ The number of seconds before the presigned URL expires.Must be an integer and `>=1` and `<=604800` (maximum of 7 days)## See also--- [`getS3Object()`](/docs/lambda/gets3object)diff --git a/packages/lambda/remotionlambda.zip b/packages/lambda/remotionlambda.zipindex b8c2857396..564385d9e2 100644Binary files a/packages/lambda/remotionlambda.zip and b/packages/lambda/remotionlambda.zip differdiff --git a/packages/lambda/src/api/get-aws-clients.ts b/packages/lambda/src/api/get-aws-clients.tsnew file mode 100644index 0000000000..933420f668--- /dev/null+++ b/packages/lambda/src/api/get-aws-clients.ts@@ -0,0 +1,24 @@+import * as cloudwatchSdk from '@aws-sdk/client-cloudwatch-logs';+import * as iamSdk from '@aws-sdk/client-iam';+import * as lambdaSdk from '@aws-sdk/client-lambda';+import * as s3Sdk from '@aws-sdk/client-s3';+import {AwsRegion} from '../client';+import {+ getCloudWatchLogsClient,+ getIamClient,+ getLambdaClient,+ getS3Client,+} from '../shared/aws-clients';++export const getAwsClients = (region: AwsRegion) => {+ return {+ s3Client: () => getS3Client(region),+ iamClient: () => getIamClient(region),+ cloudwatchClient: () => getCloudWatchLogsClient(region),+ lambdaClient: () => getLambdaClient(region),+ cloudwatchSdk,+ iamSdk,+ lambdaSdk,+ s3Sdk,+ };+};diff --git a/packages/lambda/src/api/get-s3-object.ts b/packages/lambda/src/api/get-s3-object.tsdeleted file mode 100644index 237dee737e..0000000000--- a/packages/lambda/src/api/get-s3-object.ts+++ /dev/null@@ -1,38 +0,0 @@-import {GetObjectCommand} from '@aws-sdk/client-s3';-import {Readable} from 'stream';-import {AwsRegion} from '../pricing/aws-regions';-import {getS3Client} from '../shared/aws-clients';-import {validateBucketName} from '../shared/validate-bucketname';--export type GetS3ObjectInput = {- region: AwsRegion;- bucketName: string;- objectKey: string;-};--/**- * @description Retrieves an object stored in Remotion's S3 bucket.- * @link https://v3.remotion.dev/docs/lambda/gets3object- * @param {AwsRegion} params.region The region in which the S3 bucket resides in.- * @param {string} params.bucketName The name of the bucket to fetch the object from.- * @param {string} params.objectKey Key of the S3 object to get.- * @returns {Promise<Readable>} A `stream.Readable` object.- */-export const getS3Object = async ({- region,- bucketName,- objectKey,-}: GetS3ObjectInput): Promise<Readable> => {- validateBucketName(bucketName);-- const s3Client = getS3Client(region);-- const data = await s3Client.send(- new GetObjectCommand({- Bucket: bucketName,- Key: objectKey,- })- );-- return data.Body as Readable;-};diff --git a/packages/lambda/src/index.ts b/packages/lambda/src/index.tsindex 73b22e44f8..c53a2e2733 100644--- a/packages/lambda/src/index.ts+++ b/packages/lambda/src/index.ts@@ -13,6 +13,7 @@ import {downloadVideo,} from './api/download-media';import {estimatePrice, EstimatePriceInput} from './api/estimate-price';+import {getAwsClients} from './api/get-aws-clients';import {FunctionInfo,getFunctionInfo,@@ -36,6 +37,7 @@ import {getRolePolicy,getUserPolicy,} from './api/iam-validation/suggested-policy';+import {presignUrl} from './api/presign-url';import {renderMediaOnLambda,RenderMediaOnLambdaInput,@@ -73,6 +75,8 @@ export {LambdaInternals,renderStillOnLambda,getRegions,+ getAwsClients,+ presignUrl,};export type {AwsRegion,diff --git a/packages/lambda/src/shared/aws-clients.ts b/packages/lambda/src/shared/aws-clients.tsindex 43af9c2485..14d160379d 100644--- a/packages/lambda/src/shared/aws-clients.ts+++ b/packages/lambda/src/shared/aws-clients.ts@@ -35,10 +35,31 @@ const getCredentials = () => {const getCredentialsKey = () => JSON.stringify(getCredentials());-export const getServiceClient = (+type ServiceMapping =+ | {+ type: 'cloudwatch';+ client: CloudWatchLogsClient;+ }+ | {+ type: 'lambda';+ client: LambdaClient;+ }+ | {+ type: 's3';+ client: S3Client;+ }+ | {+ type: 'iam';+ client: IAMClient;+ };++export const getServiceClient = <+ T extends ServiceMapping,+ V extends T['type'] = 's3'+>(region: AwsRegion,- service: 'cloudwatch' | 'lambda' | 's3' | 'iam'-): CloudWatchLogsClient => {+ service: V+): T['client'] => {if (!_clients[region]) {_clients[region] = {};}