Skip to content

Conversation

ychjamie
Copy link

@ychjamie ychjamie commented Sep 16, 2025

Issue # (if applicable)

Closes #35487.

Reason for this change

The BucketDeployment construct's Lambda custom resource uses a default memory limit of 128MB, which causes extremely poor S3 sync performance (10s of KB/s) and deployment timeouts. Users reported 15-minute timeouts when deploying typical static website assets, making the construct unreliable for production use without manual memory configuration.

Description of changes

Introduced a feature flag @aws-cdk/aws-s3-deployment:use512MbMemory to increase the default memory limit for BucketDeployment Lambda custom resource from 128MB to 512MB, providing dramatically improved S3 sync performance out of the box while maintaining backward compatibility.

Key Changes:

  • Added feature flag @aws-cdk/aws-s3-deployment:use512MbMemory (enabled by default in recommended-feature-flags.json)
  • When feature flag is enabled: uses 512MB explicit memory for optimal performance
  • When feature flag is disabled: uses no explicit memory limit (Lambda's default 128MB for legacy behavior)
  • Updated UUID generation logic to properly handle the new default for singleton behavior
  • Added comprehensive unit tests to verify feature flag behavior:
    • no explicit memory limit when feature flag is disabled - verifies no MemorySize property is set
    • default memory limit is 512MB when feature flag is enabled - verifies MemorySize: 512
  • Updated JSDoc documentation (default 512) and README.md to reflect new default
  • Maintained full backward compatibility - existing explicit memory configurations unchanged

Describe any new or updated permissions being added

N/A - No IAM permissions or resource access changes. This is purely a Lambda memory configuration adjustment controlled by a feature flag.

Description of how you validated changes

Unit tests:

  • Added "default memory limit is 512MB when feature flag is enabled" test that verifies CloudFormation template generation with correct MemorySize property
  • Added "no explicit memory limit when feature flag is disabled" test for backward compatibility - verifies no MemorySize property is set when flag is disabled
  • All existing tests continue to pass (79/79 pass in aws-s3-deployment module)

Integration tests:

  • All aws-s3-deployment integration tests pass successfully with no regressions
  • CloudFormation template generation verified to produce correct Lambda memory configuration with feature flag enabled/disabled

Feature flag testing:

  • Verified behavior with feature flag enabled (512MB explicit memory)
  • Verified behavior with feature flag disabled (no explicit memory, uses Lambda default 128MB)
  • Confirmed UUID generation works correctly for singleton behavior in both modes

Build verification:

  • Full TypeScript compilation, linting, and JSII build passes with no errors
  • Cross-module testing: No regressions detected across all aws-cdk-lib modules

Performance validation:

  • Issue reporter confirmed 100x performance improvement (KB/s → MB/s) with higher memory allocation
  • Feature flag allows gradual rollout and easy rollback if needed

Implementation Details

The implementation follows the feature flag pattern where:

memorySize: props.memoryLimit ?? (FeatureFlags.of(this).isEnabled(cxapi.S3_DEPLOYMENT_USE_512MB_MEMORY) ? 512 : undefined)
  • If memoryLimit is explicitly provided, use that value
  • If not provided and feature flag is enabled, use 512MB
  • If not provided and feature flag is disabled, use undefined (Lambda default 128MB)

This ensures backward compatibility while providing better defaults for new deployments.

Checklist


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

@aws-cdk-automation aws-cdk-automation requested a review from a team September 16, 2025 00:21
@github-actions github-actions bot added beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. p2 labels Sep 16, 2025
Copy link
Collaborator

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

Choose a reason for hiding this comment

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

(This review is outdated)

@pahud pahud changed the title fix(s3-deployment): increase default memory limit from 128MB to 512MB chore(s3-deployment): increase default memory limit from 128MB to 512MB Sep 16, 2025
@pahud pahud self-assigned this Sep 16, 2025
@aws-cdk-automation aws-cdk-automation dismissed their stale review September 16, 2025 00:51

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

@pahud pahud closed this Sep 16, 2025
Copy link
Contributor

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 16, 2025
@pahud pahud reopened this Sep 16, 2025
@pahud
Copy link
Contributor

pahud commented Sep 16, 2025

As discussed #35487 (comment) changing this default value would be a breaking change, I think we should introduce a feature flag for that.

@ychjamie ychjamie force-pushed the fix-35487-bucket-deployment-memory branch from 5dcc65b to 4a99c01 Compare September 17, 2025 00:01
Jamie Yang added 3 commits September 16, 2025 17:16
- Update BucketDeployment default memory limit from 128MB to 512MB for better S3 sync performance
- Add test to verify new default memory behavior
- Update documentation to reflect new default
- Maintain backward compatibility for explicit memory configurations

Fixes aws#35487
- Add @aws-cdk/aws-s3-deployment:defaultMemoryLimit feature flag
- When enabled: uses 512MB default memory (performance optimized)
- When disabled: uses 128MB default memory (legacy behavior)
- Maintains full backward compatibility
- Users can still override with explicit memoryLimit values
- Addresses PR feedback about breaking changes

Closes aws#35487
…test

- Add new feature flag to expected defaults in features.test.ts
- Feature flag defaults to false (disabled) for backward compatibility
- Fixes CI test failure for feature flag defaults validation
@pahud pahud marked this pull request as ready for review September 22, 2025 12:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(aws-s3-deployment): CDKBucketDeployment custom resource poor s3 sync performance
3 participants