Skip to content

chore(lambda): ephemeral storage validation error shows [object Object] - #38622

Open
badmintoncryer wants to merge 1 commit into
aws:mainfrom
badmintoncryer:fix/lambda-ephemeral-storage-error-message
Open

chore(lambda): ephemeral storage validation error shows [object Object]#38622
badmintoncryer wants to merge 1 commit into
aws:mainfrom
badmintoncryer:fix/lambda-ephemeral-storage-error-message

Conversation

@badmintoncryer

Copy link
Copy Markdown
Contributor

Issue # (if applicable)

Closes #38621.

Reason for this change

When ephemeralStorageSize is out of the allowed range, the validation error interpolates the Size object straight into the message. Size has no toString(), so the value renders as [object Object] and users cannot tell which value they actually passed:

«EphemeralStorageOutOfRange» Ephemeral storage size must be between 512 and 10240 MB, received [object Object].

Reproduction:

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
});

Description of changes

aws-lambda/lib/function.ts now calls .toMebibytes() on the size when building the message and states the unit explicitly, so the error reads:

Ephemeral storage size must be between 512 and 10240 MB, received 100 MiB.

Notes on why this is safe:

  • The surrounding range check already calls .toMebibytes() on the very same value, so this adds no new conversion failure path — a Size that cannot be converted into whole mebibytes already throws before reaching this line.
  • The value is guaranteed to be resolved here, because the condition guards on !props.ephemeralStorageSize.isUnresolved().

Alternative considered and not taken here: adding toString() to Size in core (Duration already has one, so Size is the odd one out). That would address this class of problem globally, but it adds public API to core and deserves its own discussion. As far as I could find, this is the only place in aws-cdk-lib today where a Size-typed value is interpolated into a message, so a local fix is sufficient for this bug.

Describe any new or updated permissions being added

None.

Description of how you validated changes

Unit tests in aws-lambda/test/function.test.ts:

  • Strengthened the existing throws if ephemeral storage size is out of bound case to assert the reported value (received 511 MiB) rather than only the prefix.
  • Added a case passing Size.gibibytes(11) to confirm the size is reported normalized to MiB (received 11264 MiB).

Both cases fail on main with received [object Object]. and pass with this change.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions Bot added p2 distinguished-contributor [Pilot] contributed 50+ PRs to the CDK labels Aug 21, 2026
@aws-cdk-automation
aws-cdk-automation requested a review from a team August 21, 2026 14:12

@aws-cdk-automation aws-cdk-automation left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This review is outdated)

@badmintoncryer badmintoncryer changed the title fix(lambda): ephemeral storage validation error shows [object Object] chore(lambda): ephemeral storage validation error shows [object Object] Aug 21, 2026
@aws-cdk-automation
aws-cdk-automation dismissed their stale review August 21, 2026 14:21

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

distinguished-contributor [Pilot] contributed 50+ PRs to the CDK p2 pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(aws-lambda): ephemeral storage validation error reports [object Object] instead of the received size

2 participants