@@ -29,11 +29,25 @@ import { buildDeps, BuildDepsRequest } from "./build_deps";
29
29
import { ConvexError , JSONValue } from "convex/values" ;
30
30
import { logDebug , logDurationMs } from "./log" ;
31
31
32
+ // Small hack to detect if we're running in the dynamic or static lambda.
33
+ const AWS_LAMBDA_EXECUTOR_TYPE = (
34
+ process . env . AWS_LAMBDA_FUNCTION_NAME ?? ""
35
+ ) . endsWith ( "-d" )
36
+ ? "DYNAMIC"
37
+ : "STATIC" ;
38
+
32
39
const AWS_LAMBDA_FUNCTION_MEMORY_SIZE = parseInt (
33
40
process . env . AWS_LAMBDA_FUNCTION_MEMORY_SIZE ?? "512" ,
34
41
10 ,
35
42
) ;
36
43
44
+ // We allocate extra memory (4GB) for dynamic lambdas, but don't want to charge customers for this implementation detail.
45
+ // We report 512MB (which may be an undercharge) but this should only be a temporary state while the static lambda deploys.
46
+ const AWS_LAMBDA_BILLED_MEMORY_SIZE =
47
+ AWS_LAMBDA_EXECUTOR_TYPE === "DYNAMIC"
48
+ ? 512
49
+ : AWS_LAMBDA_FUNCTION_MEMORY_SIZE ;
50
+
37
51
// When we bundle commonJS modules as ESM with esbuild, the bundled code might still use
38
52
// `require`, exports, module, __dirname or __filename despite being in ESM.
39
53
//
@@ -102,6 +116,14 @@ export async function invoke(
102
116
103
117
logDurationMs ( "Total invocation time" , start ) ;
104
118
logDebug ( `Memory allocated: ${ AWS_LAMBDA_FUNCTION_MEMORY_SIZE } MB` ) ;
119
+ if (
120
+ AWS_LAMBDA_EXECUTOR_TYPE === "DYNAMIC" &&
121
+ AWS_LAMBDA_BILLED_MEMORY_SIZE !== AWS_LAMBDA_FUNCTION_MEMORY_SIZE
122
+ ) {
123
+ logDebug (
124
+ `Dynamic executor used: reporting ${ AWS_LAMBDA_BILLED_MEMORY_SIZE } MB of billed memory` ,
125
+ ) ;
126
+ }
105
127
responseStream . write ( JSON . stringify ( result ) ) ;
106
128
}
107
129
@@ -232,7 +254,7 @@ export async function execute(
232
254
downloadTimeMs,
233
255
totalExecutorTimeMs,
234
256
syscallTrace : syscalls . syscallTrace ,
235
- memoryAllocatedMb : AWS_LAMBDA_FUNCTION_MEMORY_SIZE ,
257
+ memoryAllocatedMb : AWS_LAMBDA_BILLED_MEMORY_SIZE ,
236
258
} ;
237
259
}
238
260
0 commit comments