Skip to main content

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 URL
constproxyUrl='http://your-proxy-server:8080';
// Create a proxy agent
constproxyAgent=newHttpsProxyAgent(proxyUrl);
// Create a request handler that uses the proxy
exportconstproxyRequestHandler= {
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 authentication
constproxyUrl='http://username:password@your-proxy-server:8080';
constproxyAgent=newHttpsProxyAgent(proxyUrl);
exportconstauthenticatedProxyRequestHandler= {
httpsAgent: proxyAgent,
};

TypeScript support

Remotion Lambda exports a RequestHandler type that you can use for type safety:

tsx
importtype {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';
importtype {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 behavior
returnundefined;
};
exportconstrequestHandler=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
});

See also

AltStyle によって変換されたページ (->オリジナル) /