-
Notifications
You must be signed in to change notification settings - Fork 102
Add ephemeralStorageSizeMB option to defineFunction #2283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
8ac0e87
b30ad27
b3b15d4
7ad9e3f
6594212
c802c7c
6c8d04f
847124a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@aws-amplify/backend-function': minor | ||
--- | ||
|
||
Add ephemeralStorageSize option to defineFunction |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ import { | |
SsmEnvironmentEntry, | ||
StackProvider, | ||
} from '@aws-amplify/plugin-types'; | ||
import { Duration, Stack, Tags } from 'aws-cdk-lib'; | ||
import { Duration, Size, Stack, Tags } from 'aws-cdk-lib'; | ||
import { Rule } from 'aws-cdk-lib/aws-events'; | ||
import * as targets from 'aws-cdk-lib/aws-events-targets'; | ||
import { Policy } from 'aws-cdk-lib/aws-iam'; | ||
|
@@ -115,6 +115,13 @@ export type FunctionProps = { | |
*/ | ||
memoryMB?: number; | ||
|
||
/** | ||
* The size of the function's /tmp directory in MiB. | ||
* Must be a whole number. | ||
* Default is 512MiB. | ||
josefaidt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
*/ | ||
ephemeralStorageSize?: number; | ||
|
||
/** | ||
* Environment variables that will be available during function execution | ||
*/ | ||
|
@@ -232,6 +239,7 @@ class FunctionFactory implements ConstructFactory<AmplifyFunction> { | |
entry: this.resolveEntry(), | ||
timeoutSeconds: this.resolveTimeout(), | ||
memoryMB: this.resolveMemory(), | ||
ephemeralStorageSize: this.resolveEphemeralStorageSize(), | ||
environment: this.props.environment ?? {}, | ||
runtime: this.resolveRuntime(), | ||
schedule: this.resolveSchedule(), | ||
|
@@ -318,6 +326,27 @@ class FunctionFactory implements ConstructFactory<AmplifyFunction> { | |
return this.props.memoryMB; | ||
}; | ||
|
||
private resolveEphemeralStorageSize = () => { | ||
const ephemeralStorageSizeMin = 512; | ||
const ephemeralStorageSizeMax = 10240; | ||
const ephemeralStorageSizeDefault = 512; | ||
if (this.props.ephemeralStorageSize === undefined) { | ||
return ephemeralStorageSizeDefault; | ||
} | ||
if ( | ||
!isWholeNumberBetweenInclusive( | ||
this.props.ephemeralStorageSize, | ||
ephemeralStorageSizeMin, | ||
ephemeralStorageSizeMax | ||
) | ||
) { | ||
throw new Error( | ||
|
||
`ephemeralStorageSize must be a whole number between ${ephemeralStorageSizeMin} and ${ephemeralStorageSizeMax} inclusive` | ||
); | ||
} | ||
return this.props.ephemeralStorageSize; | ||
}; | ||
|
||
private resolveRuntime = () => { | ||
const runtimeDefault = 18; | ||
|
||
|
@@ -465,6 +494,7 @@ class AmplifyFunction | |
entry: props.entry, | ||
timeout: Duration.seconds(props.timeoutSeconds), | ||
memorySize: props.memoryMB, | ||
ephemeralStorageSize: Size.mebibytes(props.ephemeralStorageSize), | ||
runtime: nodeVersionMap[props.runtime], | ||
layers: props.resolvedLayers, | ||
bundling: { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -627,7 +627,7 @@ export type CustomClientConfig = { | |
export const DEFAULT_CLIENT_CONFIG_VERSION: ClientConfigVersion; | ||
|
||
// @public | ||
export const generateClientConfig: <T extends "1" | "1.1" | "1.2" | "1.3" | "0">(backendIdentifier: DeployedBackendIdentifier, version: T, awsClientProvider?: AWSClientProvider<{ | ||
export const generateClientConfig: <T extends "1.3" | "0" | "1" | "1.1" | "1.2">(backendIdentifier: DeployedBackendIdentifier, version: T, awsClientProvider?: AWSClientProvider<{ | ||
|
||
getS3Client: S3Client; | ||
getAmplifyClient: AmplifyClient; | ||
getCloudFormationClient: CloudFormationClient; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we suffix this with
MB
? we do that in property above.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some context:
It seems that CDK is just passing through this value:
see https://github.com/aws/aws-cdk/blob/b5c21890cf67ddda78c18eb0425f11a59fcadb34/packages/aws-cdk-lib/aws-lambda/lib/function.ts#L1057
and perhaps multiplies it by 1024 if necessary.
see https://github.com/aws/aws-cdk/blob/62a0638e325024fc0469ed50f9accd448d87bac7/packages/aws-cdk-lib/core/lib/size.ts#L133
But the lambda claims it's
MB
notMiB
here https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-ephemeralstorage.html .To confirm this. It might be good to deploy lambda with
ephemeralStorageSize
given to CDK construct and checking what value is printed in the AWS Console.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sobolk
In CloudFormation and AWS Console, the unit of ehpemeralStorageSize for Lambda was
MB
.I understood that only CDK uses
MiB
as a unit and it is appropriate to give MB to the suffix in Amplify.I fixed the part of JSDoc for ephemeralStorageSizeMB that used
MiB
has been corrected toMB
.Thank you very much.