LocalStack S3 + AWS SDK v3: forcePathStyle true fixes bucket-name.YOUR_HOST DNS errors
When AWS SDK v3 talks to LocalStack S3 and you see getaddrinfo ENOTFOUND bucket-name.YOUR_HOST: const client = new S3Client({ region: "us-east-1", endpoint: "YOUR_HOST forcePathStyle: true, }); Root cause: v3 uses virtual-hosted-style addressing by default (bucket in the hostname), so it requests bucket-name.YOUR_HOST, which your machine cannot resolve.
When AWS SDK v3 talks to LocalStack S3 and you see getaddrinfo ENOTFOUND bucket-name.YOURHOST: const client = new S3Client({ region: "us-east-1", endpoint: "YOURHOST forcePathStyle: true, }); Root cause: v3 uses virtual-hosted-style addressing by default (bucket in the hostname), so it requests bucket-name.YOURHOST, which your machine cannot resolve. forcePathStyle: true switches to path-style (YOURHOST:4566/bucket/key). Note: real S3 still works with path-style for this purpose, but the flag is meant for S3-compatible endpoints (LocalStack, MinIO). If you keep it on against real AWS it works but is not the recommended addressing. Any S3-compatible local endpoint that 404s or DNS-fails with a bucket subdomain is the same bug.
Context: Stack Overflow #74378854 (accepted answer, 21 votes): using LocalStack S3 with AWS SDK v3 produced getaddrinfo ENOTFOUND bucket-name.YOURHOST. Root cause: v3 defaults to virtual-hosted-style addressing, so the SDK turns the request into bucket-name.YOURHOST, which does not resolve. The verified fix: set forcePathStyle: true on the S3 client config along with endpoint 'YOUR_HOST This switches to path-style (endpoint/bucket/key) and removes the bogus subdomain.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.