fix: bucket URL is incorrect for local S3 emulators#1625
fix: bucket URL is incorrect for local S3 emulators#1625peter-smith-phd wants to merge 4 commits into
Conversation
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.
|
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 So, we could automatically set The most accurate solution would be to detect |
|
I think I would like that better, yes. I'm debating whether it would be beneficial to check the URL and see if it ends in one of the AWS domains ( But to be frank, I don't know enough about the various network configurations people could run to know if that's exhaustive enough or not, or people would want virtual hosts with custom domains as well... so probably doing the following will do the most good for the most people:
|
In addition to the explicit `CDK_S3_FORCE_PATH_STYLE` environment variable, path-style addressing is now enabled automatically when the configured S3 endpoint (`AWS_ENDPOINT_URL_S3`, falling back to `AWS_ENDPOINT_URL`) points at a loopback host such as `localhost` or `127.0.0.1`, so local S3 emulators work without extra configuration. The detection logic is shared between `cdk-assets-lib` and `toolkit-lib` via the `@aws-cdk/private-tools` package instead of being duplicated in each. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Thanks, that sounds like a plan. I suspect that I've updated the PR, and have created a shared package (based off how |
CDK_S3_FORCE_PATH_STYLE forces S3 path-style addressingSigned-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1625 +/- ##
=======================================
Coverage 88.73% 88.73%
=======================================
Files 77 77
Lines 11359 11359
Branches 1584 1585 +1
=======================================
Hits 10079 10079
Misses 1250 1250
Partials 30 30
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.There are two ways to enable path-style addressing on the S3 clients, used for asset publishing (
cdk-assets-lib) and by the toolkit (toolkit-lib).AWS_ENDPOINT_URL(orAWS_ENDPOINT_URL_S3) to use a local loopback host, such aslocalhost,127.0.0.1or::1.CDK_S3_FORCE_PATH_STYLEenvironment variable to explicitly enable the feature. This name follows the existing convention of CDK-specific environment variables such asCDK_DOCKERandCDK_HOME.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license