Skip to content

feat(lambda): add s3 object storage mode#38278

Open
antespajic wants to merge 4 commits into
aws:mainfrom
antespajic:feat/lambda-s3-object-storage-mode
Open

feat(lambda): add s3 object storage mode#38278
antespajic wants to merge 4 commits into
aws:mainfrom
antespajic:feat/lambda-s3-object-storage-mode

Conversation

@antespajic

Copy link
Copy Markdown

Issue # (if applicable)

Closes #38260.

Reason for this change

Lambda supports self-managed S3 code storage through S3ObjectStorageMode, but the Lambda L2 constructs did not expose it. Customers had to use L1 escape hatches to configure functions and layers to reference code directly from their own S3 bucket.

Description of changes

Add S3ObjectStorageMode and expose s3ObjectStorageMode on Code.fromBucketV2() options. The setting is carried through CodeConfig and rendered into both CfnFunction.CodeProperty.s3ObjectStorageMode and CfnLayerVersion.ContentProperty.s3ObjectStorageMode.

REFERENCE requires an S3 object version, so S3CodeV2 now validates that objectVersion is set for that mode. This covers both Code.fromBucketV2() and direct new S3CodeV2(...) usage.

The generated L1 model already contains s3ObjectStorageMode for Function and LayerVersion, so this does not use addPropertyOverride. cloudformation-validate still lags the generated L1 model for this property, so the validator plugin ignores only the two exact Lambda F3002 diagnostics instead of adding a broad construct-level acknowledgement.

Describe any new or updated permissions being added

No new permissions are automatically added by the L2 API. When using S3ObjectStorageMode.REFERENCE, the source bucket policy must allow the Lambda service principal to read the referenced object/version; the README and integ test show this requirement.

Description of how you validated changes

  • NX_DAEMON=false npx lerna run build --scope=aws-cdk-lib --stream
  • npx jest aws-lambda/test/code.test.ts aws-lambda/test/function.test.ts aws-lambda/test/layers.test.ts --coverage=false
  • npx integ-runner --language javascript --directory test/aws-lambda/test integ.lambda-s3-object-storage-mode.js --dry-run --update-on-failed --force --strict
  • git diff --check HEAD^ HEAD

Checklist


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

@antespajic
antespajic requested a review from a team as a code owner July 9, 2026 19:54
@github-actions github-actions Bot added effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2 labels Jul 9, 2026
@aws-cdk-automation
aws-cdk-automation requested a review from a team July 9, 2026 19:54
@github-actions github-actions Bot added the beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK label Jul 9, 2026
@antespajic
antespajic force-pushed the feat/lambda-s3-object-storage-mode branch from a9ddd1c to d6ae97d Compare July 9, 2026 19:57
@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 Jul 13, 2026
@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jul 13, 2026
Comment thread packages/aws-cdk-lib/aws-lambda/lib/function.ts Outdated
Comment thread packages/aws-cdk-lib/aws-lambda/lib/layers.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(lambda): add s3ObjectStorageMode (Self-managed S3 code storage) support to L2 constructs

3 participants