@@ -26,7 +26,7 @@ import {
26
26
SsmEnvironmentEntry ,
27
27
StackProvider ,
28
28
} from '@aws-amplify/plugin-types' ;
29
- import { Duration , Stack , Tags } from 'aws-cdk-lib' ;
29
+ import { Duration , Size , Stack , Tags } from 'aws-cdk-lib' ;
30
30
import { Rule } from 'aws-cdk-lib/aws-events' ;
31
31
import * as targets from 'aws-cdk-lib/aws-events-targets' ;
32
32
import { Policy } from 'aws-cdk-lib/aws-iam' ;
@@ -115,6 +115,13 @@ export type FunctionProps = {
115
115
*/
116
116
memoryMB ?: number ;
117
117
118
+ /**
119
+ * The size of the function's /tmp directory in MB.
120
+ * Must be a whole number.
121
+ * @default 512
122
+ */
123
+ ephemeralStorageSizeMB ?: number ;
124
+
118
125
/**
119
126
* Environment variables that will be available during function execution
120
127
*/
@@ -236,6 +243,7 @@ class FunctionFactory implements ConstructFactory<AmplifyFunction> {
236
243
entry : this . resolveEntry ( ) ,
237
244
timeoutSeconds : this . resolveTimeout ( ) ,
238
245
memoryMB : this . resolveMemory ( ) ,
246
+ ephemeralStorageSizeMB : this . resolveEphemeralStorageSize ( ) ,
239
247
environment : this . resolveEnvironment ( ) ,
240
248
runtime : this . resolveRuntime ( ) ,
241
249
schedule : this . resolveSchedule ( ) ,
@@ -324,6 +332,28 @@ class FunctionFactory implements ConstructFactory<AmplifyFunction> {
324
332
return this . props . memoryMB ;
325
333
} ;
326
334
335
+ private resolveEphemeralStorageSize = ( ) => {
336
+ const ephemeralStorageSizeMin = 512 ;
337
+ const ephemeralStorageSizeMax = 10240 ;
338
+ const ephemeralStorageSizeDefault = 512 ;
339
+ if ( this . props . ephemeralStorageSizeMB === undefined ) {
340
+ return ephemeralStorageSizeDefault ;
341
+ }
342
+ if (
343
+ ! isWholeNumberBetweenInclusive (
344
+ this . props . ephemeralStorageSizeMB ,
345
+ ephemeralStorageSizeMin ,
346
+ ephemeralStorageSizeMax
347
+ )
348
+ ) {
349
+ throw new AmplifyUserError ( 'InvalidEphemeralStorageSizeMBError' , {
350
+ message : `Invalid function ephemeralStorageSizeMB of ${ this . props . ephemeralStorageSizeMB } ` ,
351
+ resolution : `ephemeralStorageSizeMB must be a whole number between ${ ephemeralStorageSizeMin } and ${ ephemeralStorageSizeMax } inclusive` ,
352
+ } ) ;
353
+ }
354
+ return this . props . ephemeralStorageSizeMB ;
355
+ } ;
356
+
327
357
private resolveEnvironment = ( ) => {
328
358
if ( this . props . environment === undefined ) {
329
359
return { } ;
@@ -509,6 +539,7 @@ class AmplifyFunction
509
539
entry : props . entry ,
510
540
timeout : Duration . seconds ( props . timeoutSeconds ) ,
511
541
memorySize : props . memoryMB ,
542
+ ephemeralStorageSize : Size . mebibytes ( props . ephemeralStorageSizeMB ) ,
512
543
runtime : nodeVersionMap [ props . runtime ] ,
513
544
layers : props . resolvedLayers ,
514
545
bundling : {
0 commit comments