localstack / localstack/localstack-python-client

[Feature] Support virtual host S3 API calls

Open
#52 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
191
Forks
31
PR merge metrics
No merged PRs in 30d

Description

After struggling for several hours with Docker Compose, I noticed my problem was actually in this library, which does not seem to support the virtual host addressing for the `s3` client.

Looking at `boto3` in debug mode, I noticed that when using Virtual host addressing, the HTTP request was aimed towards `http://.:`. This is not a valid endpoint, and it should be `http://.s3.:`, as described [here](https://docs.localstack.cloud/user-guide/aws/s3/#path-style-and-virtual-hosted-style-requests).

After delving deeper I noticed `localstack_client.config.get_endpoint` it is not handling `s3` in any special way. I manually patched the function and noticed that with a simple

```python3
def new_get_service_endpoint(
service: str, localstack_host: Optional[str] = None
) -> Optional[str]:
endpoints = localstack_client.config.get_service_endpoints(localstack_host=localstack_host)
endpoint = endpoints.get(service)
if service == "s3":
endpoint = "http://s3." + endpoint.split("http://")[1]
return endpoint
```

I know this doesn't handle SSL, it's just a draft. It works for both virtual and path based addressing.

I see three ways simple about this:
1. Do not support virtual host addressing. This is a problem, as in theory AWS is deprecating path based addressing (also it has been deprecating it for 4 years, so...)
2. Do a hack like the one proposed.
3. Honor AWS service specific endpoints through envars (for instance `AWS_ENDPOINT_URL_S3`) and leave it up to the user to set it up (with appropriate documentation, at least in the `README.md`).

What are your thoughts on this?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading localstack_client.config.get_endpoint and get_service_endpoints, then reproduce the S3 request with boto3 debug logging and Docker Compose. Review the README.md endpoint guidance and determine which of the three proposed approaches the project should adopt; done should include a decided, working virtual-host addressing path and corresponding documentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, python
Domain
api, cloud
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.