Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnknownHostException: localhost.localstack.cloud on mac os #68

Open
vicmosin opened this issue Aug 10, 2021 · 3 comments
Open

UnknownHostException: localhost.localstack.cloud on mac os #68

vicmosin opened this issue Aug 10, 2021 · 3 comments

Comments

@vicmosin
Copy link

I am using 0.2.15 version of the utils. The docker starts up without any issue, but the s3 client can not resolve the url.. here is the config I have:

@ExtendWith(LocalstackDockerExtension::class)
@LocalstackDockerProperties(services = [ServiceName.S3])
@SpringBootTest(classes = [Application::class, SomeControllerTest.S3TestConfiguration::class])
@TestPropertySource(
    properties = ["spring.main.allow-bean-definition-overriding=true"]
)
class SomeControllerTest : AbstractTest() {

    @Configuration
    class S3TestConfiguration {

        // override existing s3 client
        @Primary
        @Bean
        fun s3Client(): S3Client =
            S3Client.builder()
                .credentialsProvider(
                    StaticCredentialsProvider.create(
                        AwsBasicCredentials.create(
                            "key", "secret"
                        )))
                .endpointOverride(URI.create(Localstack.INSTANCE.endpointS3))
                .region(Region.AWS_GLOBAL)
                .serviceConfiguration { it.pathStyleAccessEnabled() }
                .build()
    }
   ...
}
Caused by: software.amazon.awssdk.core.exception.SdkClientException: Unable to execute HTTP request: localhost.localstack.cloud
	at software.amazon.awssdk.core.exception.SdkClientException$BuilderImpl.build(SdkClientException.java:98)
...
Caused by: java.net.UnknownHostException: localhost.localstack.cloud
	at java.base/java.net.InetAddress$CachedAddresses.get(InetAddress.java:800)
@whummer
Copy link
Member

whummer commented Aug 18, 2021

Thanks for reporting @vicmosin . This hostname should be resolvable, but I guess there's a few ISPs that may be blocking it from getting resolved.

Would it be an option for you to add an entry to the /etc/hosts file?

Alternatively, you should be able to customize the API endpoint address by setting this environment variable in your LocalStack container: LOCALSTACK_HOSTNAME=127.0.0.1. Hope that helps - please keep us posted how it goes. Thanks!

@vicmosin
Copy link
Author

@whummer I finally had a time to check proposed solution..
Changing hosts file indeed not an option. And regarding the environment variable - can you please elaborate how exactly it must be set from the test? I tried the following way and it didn't work:

@LocalstackDockerProperties(services = [ServiceName.S3], environmentVariableProvider = DefaultEnvironmentVariableProvider::class)
...
class DefaultEnvironmentVariableProvider : IEnvironmentVariableProvider {

    override fun getEnvironmentVariables(): MutableMap<String, String> =
        mutableMapOf("LOCALSTACK_HOSTNAME" to "127.0.0.1")
}

@kamuzari
Copy link

kamuzari commented Mar 23, 2023

Me too.

The endpoints are entered in a strange combination.

I am currently using mac os, and when connecting localstack and application through docker-compose, it is assembled as a strange endpoint.

The bucket name and the container name are concatenated with ., and the endpoint is passed, resulting in an UnknownHostException.

Especially when creating a bucket by code, an exception is thrown.

code >>
amazonS3.deleteBucket(new DeleteBucketRequest(localStackProperty.bucket()));
amazonS3.createBucket(new CreateBucketRequest(localStackProperty.bucket(), region));

Caused by: com.amazonaws.SdkClientException: Unable to execute HTTP request:   ${bucket_name}.${containerName}
Caused by: java.net.UnknownHostException:  ${bucket_name}.${containerName}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants