Skip to content

feat: CDK_S3_FORCE_PATH_STYLE forces S3 path-style addressing#1625

Open
peter-smith-phd wants to merge 1 commit into
aws:mainfrom
peter-smith-phd:feat/s3-force-path-style
Open

feat: CDK_S3_FORCE_PATH_STYLE forces S3 path-style addressing#1625
peter-smith-phd wants to merge 1 commit into
aws:mainfrom
peter-smith-phd:feat/s3-force-path-style

Conversation

@peter-smith-phd

Copy link
Copy Markdown

The AWS SDK addresses S3 buckets using virtual-hosted-style URLs by default (https://<bucket>.s3.amazonaws.com). When targeting custom or local S3-compatible endpoints (for example LocalStack or MinIO), path-style addressing (https://<endpoint>/<bucket>) is often required instead.

Setting the CDK_S3_FORCE_PATH_STYLE environment variable now enables path-style addressing on the S3 clients used for asset publishing (cdk-assets-lib) and by the toolkit (toolkit-lib). When the variable is unset, behavior is unchanged and the SDK default applies.

This follows the existing convention of CDK-specific environment variables such as CDK_DOCKER and CDK_HOME.

Checklist

  • Unit tests added/updated
  • Integration tests added/updated (if deploying new resource types or cross-service interactions)

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

Setting the `CDK_S3_FORCE_PATH_STYLE` environment variable enables
path-style addressing on the S3 clients used for asset publishing and
by the toolkit, which is useful when targeting custom or local S3
endpoints.
@aws-cdk-automation aws-cdk-automation requested a review from a team June 14, 2026 22:18
@github-actions github-actions Bot added the p2 label Jun 14, 2026
@peter-smith-phd peter-smith-phd marked this pull request as ready for review June 14, 2026 22:24
@rix0rrr

rix0rrr commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Is there a way to autoderive the correct behavior here? Zero-conf is better than an option fleet...

@peter-smith-phd

peter-smith-phd commented Jun 15, 2026

Copy link
Copy Markdown
Author

Is there a way to autoderive the correct behavior here? Zero-conf is better than an option fleet...

Great question. This option is solely necessary when the user sets a custom AWS_ENDPOINT_URL_S3 . If the URL they provide doesn't support subdomains properly (which is a problem for 127.0.0.1 or localhost), then S3 path-style addressing is required.

So, we could automatically set forcePathStyle if there's a change to AWS_ENDPOINT_URL_S3 (or AWS_ENDPOINT_URL that implicitly sets AWS_ENDPOINT_URL_S3). This is fine if the new URL refers to a non-AWS location (like an emulator), but could be problematic if the new URL points so something like a FIPS endpoint (prefers virtual host for performance reasons).

The most accurate solution would be to detect 127.0.0.1 and localhost explicitly, and automatically set the flag only in those cases. Would that be more acceptable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants