localstack / localstack

💻 A fully functional local AWS cloud stack. Develop and test your cloud & Serverless apps offline
https://localstack.cloud
Other
55.95k stars 3.98k forks source link

Unable to find forwarding rule for host "localhost:4566" #3453

Closed harley84 closed 3 years ago

harley84 commented 3 years ago

Type of request: This is a ...

[x] bug report [ ] feature request

Detailed description

Possibly related/duplicate of https://github.com/localstack/localstack/issues/3175 When using java client with anonymous credentials putting a new object with a slash in the key. For example:

client.putObject("testbucket", "file", "content"); // Works
client.putObject("testbucket", "subdir/file", "content"); // Fails

When faking the credentials it works (tested on 0.12.2 and 0.12.4)

Expected behavior

S3 operations work.

Actual behavior

This is a regression since version 0.10.5
The log in the container is: 2021-01-10T08:51:25:INFO:localstack.services.edge: Unable to find forwarding rule for host "localhost:4566", path "/", target header "", auth header "", data "b''"

Steps to reproduce

Command used to start LocalStack

A snippet from docker-compose:

  localstack-v2:
    container_name: localstack-v2
    image: localstack/localstack:0.12.2
    ports:
      - "4566:4566" # edge service
      - "${PORT_WEB_UI-8091}:${PORT_WEB_UI-8080}"
    environment:
      - SERVICES=s3,lambda,dynamodb,sqs
      - LAMBDA_DOCKER_NETWORK=dockerized_localenv_localenv
      - DEBUG=1
      - PORT_WEB_UI=8081
      - DATA_DIR=/tmp/localstack/data
      - DOCKER_HOST=unix:///var/run/docker.sock
    volumes:
      - ${NON_VERSIONED_FILES_BASE}/localstack-v2:/tmp/localstack
      - /var/run/docker.sock:/var/run/docker.sock
    networks:
      - localenv

Client code (AWS SDK code snippet, or sequence of "awslocal" commands)

package xxx;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AnonymousAWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import org.junit.jupiter.api.Test;

public class LocalStack {

    @Test
    void credentialsAnonymousFailsWith404() {

        AmazonS3 client = AmazonS3ClientBuilder.standard()
            .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://localhost:4566", "us-east-1"))
            .enablePathStyleAccess()
            .withCredentials(new AWSCredentialsProvider() {
                @Override
                public AWSCredentials getCredentials() {
                    return new AnonymousAWSCredentials();
                }

                @Override
                public void refresh() {

                }
            })
            .build();

        var objects = client.listObjectsV2("testbucket");
        client.createBucket("testbucket");
        objects = client.listObjectsV2("testbucket");

        client.putObject("testbucket", "file", "content");
        client.putObject("testbucket", "subdir/file", "content");
    }

    @Test
    void credentialsStaticNoErrors() {

        AmazonS3 client = AmazonS3ClientBuilder.standard()
            .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://localhost:4566", "us-east-1"))
            .enablePathStyleAccess()
            .withCredentials(new AWSCredentialsProvider() {
                @Override
                public AWSCredentials getCredentials() {
                    return new BasicAWSCredentials("AccessKey", "SecretKey");
                }

                @Override
                public void refresh() {

                }
            })
            .build();

        var buckets = client.listBuckets();
        client.createBucket("testbucket");
        buckets = client.listBuckets();

        client.putObject("testbucket", "file", "content");
        client.putObject("testbucket", "subdir/file", "content");
    }
}
whummer commented 3 years ago

Thanks for reporting @harley84 . This should be fixed in #3500 - can you please pull the latest Docker image (currently being built by Travis-CI) and give it another try? Please report here if the problem persists. Thanks