Using a proxy with Remotion Lambda
Available from v4.0.315
Remotion Lambda supports using HTTP/HTTPS proxies for all AWS API calls by accepting a requestHandler
option that allows you to pass a custom AWS SDK request handler.
This is useful when your environment requires all external HTTP requests to go through a proxy server.
Setting up a proxy
1. Install a proxy agent
First, install an HTTP/HTTPS proxy agent package like https-proxy-agent
:
bash
npm install https-proxy-agent
2. Create a request handler with proxy
Create a request handler that uses your proxy:
tsx
import {HttpsProxyAgent } from 'https-proxy-agent';// Configure your proxy URLconstproxyUrl = 'http://your-proxy-server:8080';// Create a proxy agentconstproxyAgent = newHttpsProxyAgent (proxyUrl );// Create a request handler that uses the proxyexport constproxyRequestHandler = {httpsAgent :proxyAgent ,};
3. Use the request handler with Remotion Lambda functions
Pass the requestHandler
option to any Remotion Lambda function:
tsx
import {getFunctions } from '@remotion/lambda/client';import {proxyRequestHandler } from './proxy-setup';constfunctions = awaitgetFunctions ({region : 'us-east-1',compatibleOnly : true,requestHandler :proxyRequestHandler ,});console .log ('Functions:',functions );
Supported functions
All public AWS-related APIs in the Lambda client accept the requestHandler
option.
Example with authentication
If your proxy requires authentication, you can include credentials in the proxy URL:
tsx
import {HttpsProxyAgent } from 'https-proxy-agent';// Proxy with authenticationconstproxyUrl = 'http://username:password@your-proxy-server:8080';constproxyAgent = newHttpsProxyAgent (proxyUrl );export constauthenticatedProxyRequestHandler = {httpsAgent :proxyAgent ,};
TypeScript support
Remotion Lambda exports a RequestHandler
type that you can use for type safety:
tsx
import type {RequestHandler } from '@remotion/lambda/client';import {HttpsProxyAgent } from 'https-proxy-agent';constproxyAgent = newHttpsProxyAgent ('http://proxy:8080');constmyRequestHandler :RequestHandler = {httpsAgent :proxyAgent ,};
Environment-specific configuration
You can conditionally use a proxy based on your environment:
tsx
import {HttpsProxyAgent } from 'https-proxy-agent';import type {RequestHandler } from '@remotion/lambda/client';constcreateRequestHandler = ():RequestHandler | undefined => {constproxyUrl =process .env .HTTPS_PROXY ||process .env .HTTP_PROXY ;if (proxyUrl ) {return {httpsAgent : newHttpsProxyAgent (proxyUrl ),};}// Return undefined to use default behaviorreturnundefined ;};export constrequestHandler =createRequestHandler ();
Then use it in your Lambda calls:
tsx
import {getFunctions } from '@remotion/lambda/client';import {requestHandler } from './conditional-proxy';constfunctions = awaitgetFunctions ({region : 'us-east-1',compatibleOnly : true,requestHandler , // This will be undefined if no proxy is configured});