Describe the bug
When ephemeralStorageSize on lambda.Function is outside the allowed range, the validation error interpolates the Size object directly into the message. Size has no toString(), so the value is rendered as [object Object] and there is no way to tell from the error which value was actually passed.
Regression Issue
Expected Behavior
The error states the size that was received, e.g.:
Ephemeral storage size must be between 512 and 10240 MB, received 100 MiB.
Current Behavior
«EphemeralStorageOutOfRange» Ephemeral storage size must be between 512 and 10240 MB, received [object Object].
Reproduction Steps
new lambda.Function(this, 'Fn', {
runtime: lambda.Runtime.NODEJS_20_X,
handler: 'index.handler',
code: lambda.Code.fromInline('exports.handler = async () => {};'),
ephemeralStorageSize: cdk.Size.mebibytes(100), // below the 512 MiB minimum
});
Run cdk synth.
The underlying behaviour can also be seen without synthesizing:
$ node -e "const cdk=require('aws-cdk-lib/core'); console.log(String(cdk.Size.mebibytes(100)))"
[object Object]
Possible Solution
packages/aws-cdk-lib/aws-lambda/lib/function.ts builds the message with the Size object itself:
if (props.ephemeralStorageSize && !props.ephemeralStorageSize.isUnresolved()
&& (props.ephemeralStorageSize.toMebibytes() < 512 || props.ephemeralStorageSize.toMebibytes() > 10240)) {
throw new ValidationError(lit`EphemeralStorageOutOfRange`, `Ephemeral storage size must be between 512 and 10240 MB, received ${props.ephemeralStorageSize}.`, this);
}
The range check on the line above already converts the same value with .toMebibytes(); only the message is missing the conversion. Calling .toMebibytes() in the message as well fixes it, and introduces no new failure path (a Size that cannot be converted into whole mebibytes already throws in the condition, and the value is guaranteed to be resolved by the !isUnresolved() guard).
Additional Information/Context
The root cause is that Size in core has no toString(), unlike Duration, which has both toString() and toHumanString(). Any Size interpolated into a string therefore renders as [object Object]. aws-lambda/lib/function.ts appears to be the only place in aws-cdk-lib today where that actually happens, so this issue is scoped to the Lambda message; whether Size should gain a toString() of its own is a separate discussion.
AWS CDK Library version (aws-cdk-lib)
2.261.0 (also reproduces on main)
AWS CDK CLI version
2.1131.0
Node.js Version
v20.19.2
OS
macOS 14.6.1
Language
TypeScript
Language Version
TypeScript (7.0.2)
Other information
No response
Describe the bug
When
ephemeralStorageSizeonlambda.Functionis outside the allowed range, the validation error interpolates theSizeobject directly into the message.Sizehas notoString(), so the value is rendered as[object Object]and there is no way to tell from the error which value was actually passed.Regression Issue
Expected Behavior
The error states the size that was received, e.g.:
Current Behavior
Reproduction Steps
Run
cdk synth.The underlying behaviour can also be seen without synthesizing:
Possible Solution
packages/aws-cdk-lib/aws-lambda/lib/function.tsbuilds the message with theSizeobject itself:The range check on the line above already converts the same value with
.toMebibytes(); only the message is missing the conversion. Calling.toMebibytes()in the message as well fixes it, and introduces no new failure path (aSizethat cannot be converted into whole mebibytes already throws in the condition, and the value is guaranteed to be resolved by the!isUnresolved()guard).Additional Information/Context
The root cause is that
Sizeincorehas notoString(), unlikeDuration, which has bothtoString()andtoHumanString(). AnySizeinterpolated into a string therefore renders as[object Object].aws-lambda/lib/function.tsappears to be the only place inaws-cdk-libtoday where that actually happens, so this issue is scoped to the Lambda message; whetherSizeshould gain atoString()of its own is a separate discussion.AWS CDK Library version (aws-cdk-lib)
2.261.0 (also reproduces on
main)AWS CDK CLI version
2.1131.0
Node.js Version
v20.19.2
OS
macOS 14.6.1
Language
TypeScript
Language Version
TypeScript (7.0.2)
Other information
No response