I am playing around with a localstack instance running on docker. I try to access the sns service, but receiving a error while executing methods like "listTopics()" or "createTopic()" I didnt find any help on Google yet, so may anyone has a idea whats wrong here ?
Error:
Caused by: java.lang.NoSuchFieldError: ENDPOINT_OVERRIDDEN
at com.amazonaws.services.sns.AmazonSNSClient.executeListTopics(AmazonSNSClient.java:1830) ~[aws-java-sdk-sns-1.11.875.jar:na]
at com.amazonaws.services.sns.AmazonSNSClient.listTopics(AmazonSNSClient.java:1812) ~[aws-java-sdk-sns-1.11.875.jar:na]
at com.amazonaws.services.sns.AmazonSNSClient.listTopics(AmazonSNSClient.java:1853) ~[aws-java-sdk-sns-1.11.875.jar:na]
at com.example.dockerspringboot.DockerSpringBootApplication.getSnsClient(DockerSpringBootApplication.java:62) ~[classes/:na]
at com.example.dockerspringboot.DockerSpringBootApplication$$EnhancerBySpringCGLIB$$a65fee3d.CGLIB$getSnsClient$2(<generated>) ~[classes/:na]
at com.example.dockerspringboot.DockerSpringBootApplication$$EnhancerBySpringCGLIB$$a65fee3d$$FastClassBySpringCGLIB$$99ad7dfd.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) ~[spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at com.example.dockerspringboot.DockerSpringBootApplication$$EnhancerBySpringCGLIB$$a65fee3d.getSnsClient(<generated>) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
... 98 common frames omitted
I try to access the localstack sns service via the java aws sdk:
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sns</artifactId>
<version>1.11.875</version>
</dependency>
The Code in my App where the error is thrown looks like this:
private String serviceEndpoint = "http://localhost:4566";
private String signingRegion = "eu-west-1";
@Bean
public AmazonSNS getSnsClient() {
AmazonSNS sns = AmazonSNSClient.builder().withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(serviceEndpoint, signingRegion)).withCredentials(new DefaultAWSCredentialsProviderChain()).build();
System.out.println(sns.listTopics().toString());
return sns;
}
I am running localstack on Docker with this docker-compose file:
version: '2.1'
services:
localstack:
container_name: "localstack"
image: localstack/localstack-full
network_mode: bridge
ports:
- "4566-4599:4566-4599"
- "${PORT_WEB_UI-8080}:${PORT_WEB_UI-8080}"
environment:
- SERVICES=s3,sns
- DEBUG=${DEBUG- }
- DATA_DIR=/tmp/localstack/data
- PORT_WEB_UI=${PORT_WEB_UI- }
- LAMBDA_EXECUTOR=${LAMBDA_EXECUTOR- }
- KINESIS_ERROR_PROBABILITY=${KINESIS_ERROR_PROBABILITY- }
- DOCKER_HOST=unix:///var/run/docker.sock
volumes:
- "local_vol:/tmp/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"
volumes:
local_vol:
driver: local
Creating a SNS topic via cmdline works fine, so the service is running!
/opt/code/localstack # aws --endpoint-url=http://localhost:4566 sns create-topic --name my_topic
{
"TopicArn": "arn:aws:sns:us-east-1:000000000000:my_topic"
}
/opt/code/localstack # aws --endpoint-url=http://localhost:4566 sns list-topics
{
"Topics": [
{
"TopicArn": "arn:aws:sns:us-east-1:000000000000:my_topic"
}
]
}
btw.: I do also use the S3 of localstock, this one is working - may those 2 conflict in anyway ?
Hope someone could help me, fix this. :)
If anyone run into this, i couldnt find the actual problem here, but got it working with the amazon aws sdk for java 2.0 .