Could not use S3 when using `Virtual-hosted–style`
Is there an existing issue for this?
- [X] I have searched the existing issues
Current Behavior
When using awslocal with config default.s3.addressing_style=virtual I cannot create,list or download files.
Expected Behavior
When using awslocal with config default.s3.addressing_style=virtual I should be able to create/list/download S3 files.
How are you starting LocalStack?
With a docker-compose file
Steps To Reproduce
Init
- Start a container with S3 service
- Add
127.0.0.1 treasury-x-dev.localhostto/etc/hostsin order to resolve domain.
Steps to reproduce
- Configure CLI to use
virtualaddressing style
awslocal configure set default.s3.addressing_style virtual
- Create a bucket
awslocal s3 mb s3://mybucket
- Copy local file to created bucket
awslocal s3 cp sample.csv s3://mybucket/folder/sample.csv
Getting an error
upload failed: ./sample.csv to s3://mybucket/folder/sample.csv An error occurred (NoSuchBucket) when calling the PutObject operation: The specified bucket does not exist
I tried as well to upload a file using path style, which succeeded, and then to list the file through virtual-hosted config, and I get KeyNotFound
Environment
- OS: MacOS 14.5 (23F79)
- LocalStack: 3.4.0
LocalStack version:
LocalStack Docker image sha:
LocalStack build date:
LocalStack build git hash:
Anything else?
No response
Welcome to LocalStack! Thanks for reporting your first issue and our team will be working towards fixing the issue for you or reach out for more background information. We recommend joining our Slack Community for real-time help and drop a message to LocalStack Pro Support if you are a Pro user! If you are willing to contribute towards fixing this issue, please have a look at our contributing guidelines and our contributing guide.
Hello @nicumaxian and thanks for the report!
We have a page in the documentation about S3 addressing style: https://docs.localstack.cloud/user-guide/aws/s3/#path-style-and-virtual-hosted-style-requests
In order for LocalStack to be able to understand Virtual-hosted style requests, you need your endpoint to be prefixed with s3..
With the CLI, you can use profile or config as described in this AWS page: https://docs.aws.amazon.com/sdkref/latest/guide/feature-ss-endpoints.html
There's this particular page where you can set the S3 endpoint directly: https://docs.aws.amazon.com/sdkref/latest/guide/feature-ss-endpoints.html#ss-endpoints-config
If setting default.s3.addressing_style=virtual, you should set the S3 service endpoint to s3.localhost.localstack.cloud:4566 which will automatically to resolve to 127.0.0.1.
You can try it manually by running it that way (this is without the config above):
awslocal s3 mb s3://mybucket --endpoint-url http://s3.localhost.localstack.cloud:4566
awslocal s3 cp sample.csv s3://mybucket/folder/sample.csv --endpoint-url http://s3.localhost.localstack.cloud:4566
# or also
export AWS_ENDPOINT_URL_S3=http://s3.localhost.localstack.cloud:4566
awslocal s3 mb s3://mybucket
awslocal s3 cp sample.csv s3://mybucket/folder/sample.csv
But the easiest would be to setup a profile like explained above in the documentation so that your S3 service would target the right endpoint.
I hope that answers your question, please feel free if there's any misunderstanding or issue.
Thanks!
Hello 👋! It looks like this issue hasn’t been active in longer than two weeks. We encourage you to check if this is still an issue in the latest release. In the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please feel free to provide a comment or upvote with a reaction on the initial post to prevent automatic closure. If the issue is already closed, please feel free to open a new one.