Server-Side
This guide will walk you through setting up an AWS S3 bucket and executing a Node.js script using Puppeteer to interact with Diffusion Studio. Follow the steps below to get your environment up and running.
Prerequisites
Before proceeding, ensure you have the following:
- Node.js installed on your machine.
- An AWS Account with permissions to create and configure S3 buckets.
AWS S3 Bucket Setup
Create an S3 Bucket
- Log in to the AWS Management Console.
- Navigate to the S3 service and create a new bucket.
- Note down the bucket name and region for later use.
Create an IAM User
- In the AWS Management Console, go to the IAM service.
- Create a new IAM user with programmatic access.
- Attach the
AmazonS3FullAccess
policy to this user to grant full access to S3. - Save the Access Key ID and Secret Access Key securely.
Configure CORS for the S3 Bucket
-
Go to the S3 bucket you created.
-
Navigate to the Permissions tab.
-
Under the CORS configuration section, add the following rules:
This configuration enables your application to interact with the S3 bucket without being blocked by CORS.
Project Setup
Client-Side Configuration
Create a website that assigns the core Diffusion Studio library to the global context. Below is an example of how to do this:
Ensure this website is accessible via HTTP from the server or machine where the Node.js script will run. You can achieve this by serving it with a tool like Vite.
Server-Side Configuration
The following instructions cover the Node.js setup, particularly configuring the S3 client.
Configure the S3 Client
Replace <S3_ACCESS_KEY>
, <S3_SECRET_KEY>
, and <S3_REGION>
with your actual AWS credentials and region.
Create a Function to Generate Presigned URLs
Presigned URLs allow temporary access to S3 objects. Here’s how to create one:
Replace <S3_BUCKET>
with the name of your S3 bucket.
Define the Video Processing Pipeline
This function will be executed using Puppeteer and will leverage Diffusion Studio to render a video and upload it to S3.
Execute the Script with Puppeteer
Finally, use Puppeteer to load your website, generate the presigned URL, and run the video processing function:
This script launches a headless browser, navigates to your website, and runs the video processing pipeline, uploading the output to the S3 bucket.