Skip to content

🎥 Make videos programmatically with React

add logs to deployFunction

Jonny Burgerc648039c1c39
diff --git a/packages/lambda/src/api/create-function.ts b/packages/lambda/src/api/create-function.ts
index 1b8a91f165..c51406cd50 100644
--- a/packages/lambda/src/api/create-function.ts
+++ b/packages/lambda/src/api/create-function.ts
@@ -9,6 +9,8 @@ import {
PutRuntimeManagementConfigCommand,
TagResourceCommand,
} from '@aws-sdk/client-lambda';
+import type {LogLevel} from '@remotion/renderer';
+import {RenderInternals} from '@remotion/renderer';
import {readFileSync} from 'node:fs';
import {VERSION} from 'remotion/version';
import {LOG_GROUP_PREFIX} from '../defaults';
@@ -32,6 +34,7 @@ export const createFunction = async ({
customRoleArn,
enableLambdaInsights,
enableV5Runtime,
+ logLevel,
}: {
createCloudWatchLogGroup: boolean;
region: AwsRegion;
@@ -46,30 +49,56 @@ export const createFunction = async ({
customRoleArn: string;
enableLambdaInsights: boolean;
enableV5Runtime: boolean;
+ logLevel: LogLevel;
}): Promise<{FunctionName: string}> => {
if (createCloudWatchLogGroup) {
+ RenderInternals.Log.verbose(
+ {indent: false, logLevel},
+ 'Creating CloudWatch group',
+ );
try {
await getCloudWatchLogsClient(region).send(
new CreateLogGroupCommand({
logGroupName: `${LOG_GROUP_PREFIX}${functionName}`,
}),
);
+ RenderInternals.Log.verbose(
+ {indent: false, logLevel},
+ 'CloudWatch group successfully created',
+ );
} catch (_err) {
const err = _err as Error;
- if (!err.message.includes('log group already exists')) {
+ if (err.message.includes('log group already exists')) {
+ RenderInternals.Log.verbose(
+ {indent: false, logLevel},
+ 'CloudWatch group already existed.',
+ );
+ } else {
throw err;
}
}
+ RenderInternals.Log.verbose(
+ {indent: false, logLevel},
+ 'Adding retention policy to the CloudWatch group',
+ );
await getCloudWatchLogsClient(region).send(
new PutRetentionPolicyCommand({
logGroupName: `${LOG_GROUP_PREFIX}${functionName}`,
retentionInDays,
}),
);
+ RenderInternals.Log.verbose(
+ {indent: false, logLevel},
+ `Set retention to ${retentionInDays} days`,
+ );
}
if (alreadyCreated) {
+ RenderInternals.Log.verbose(
+ {indent: false, logLevel},
+ `Function ${functionName} already existed`,
+ );
return {FunctionName: functionName};
}
@@ -79,6 +108,18 @@ export const createFunction = async ({
? v5HostedLayers[region]
: hostedLayers[region];
+ if (enableV5Runtime) {
+ RenderInternals.Log.verbose(
+ {indent: false, logLevel},
+ 'New V5 runtime enabled https://remotion.dev/docs/lambda/runtime#runtime-changes-in-remotion-50',
+ );
+ }
+
+ RenderInternals.Log.verbose(
+ {indent: false, logLevel},
+ 'Deploying new Lambda function',
+ );
+
const {FunctionName, FunctionArn} = await getLambdaClient(region).send(
new CreateFunctionCommand({
Code: {
@@ -101,6 +142,11 @@ export const createFunction = async ({
}),
);
+ RenderInternals.Log.verbose(
+ {indent: false, logLevel},
+ 'Function deployed. Adding tags...',
+ );
+
try {
await getLambdaClient(region).send(
new TagResourceCommand({
@@ -116,17 +162,34 @@ export const createFunction = async ({
);
} catch (err) {
// Previous Lambda versions had no permission to tag the function
- if (!(err as Error).name.includes('AccessDenied')) {
+ if ((err as Error).name.includes('AccessDenied')) {
+ RenderInternals.Log.verbose(
+ {indent: false, logLevel},
+ 'Did not have permission to tag the function. Skipping.',
+ );
+ } else {
throw err;
}
}
+ RenderInternals.Log.verbose(
+ {indent: false, logLevel},
+ 'Disabling function retries (Remotion handles retries itself)...',
+ );
await getLambdaClient(region).send(
new PutFunctionEventInvokeConfigCommand({
MaximumRetryAttempts: 0,
FunctionName,
}),
);
+ RenderInternals.Log.verbose(
+ {indent: false, logLevel},
+ 'Set function retries to 0.',
+ );
+ RenderInternals.Log.verbose(
+ {indent: false, logLevel},
+ 'Waiting for the function to be ready...',
+ );
let state = 'Pending';
@@ -142,6 +205,16 @@ export const createFunction = async ({
state = getFn.Configuration?.State as string;
}
+ RenderInternals.Log.verbose(
+ {indent: false, logLevel},
+ 'Function is now ready.',
+ );
+
+ RenderInternals.Log.verbose(
+ {indent: false, logLevel},
+ 'Locking the runtime version of the function...',
+ );
+
const RuntimeVersionArn = enableV5Runtime
? `arn:aws:lambda:${region}::runtime:da57c20c4b965d5b75540f6865a35fc8030358e33ec44ecfed33e90901a27a72`
: `arn:aws:lambda:${region}::runtime:b97ad873eb5228db2e7d5727cd116734cc24c92ff1381739c4400c095404a2d3`;
@@ -160,5 +233,10 @@ export const createFunction = async ({
);
}
+ RenderInternals.Log.verbose(
+ {indent: false, logLevel},
+ `Function runtime is locked to ${RuntimeVersionArn}`,
+ );
+
return {FunctionName: FunctionName as string};
};
diff --git a/packages/lambda/src/api/deploy-function.ts b/packages/lambda/src/api/deploy-function.ts
index c1bfe308a8..fe2c6d54bd 100644
--- a/packages/lambda/src/api/deploy-function.ts
+++ b/packages/lambda/src/api/deploy-function.ts
@@ -92,6 +92,7 @@ export const internalDeployFunction = async (
customRoleArn: params.customRoleArn as string,
enableLambdaInsights: params.enableLambdaInsights ?? false,
enableV5Runtime: params.enableV5Runtime,
+ logLevel: params.logLevel,
});
if (!created.FunctionName) {