Я пытаюсь опубликовать сообщение AWS SNS для конкретной темы, используя JAVA aws-sdk. Я новичок в этом и поэтому не могу понять, что не так с кодом.
package com.example.publish;
import java.io.IOException;
import java.util.UUID;
import org.apache.commons.logging.Log;
import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.regions.*;
import com.amazonaws.services.apigateway.AmazonApiGateway;
import com.amazonaws.services.apigateway.AmazonApiGatewayClientBuilder;
import com.amazonaws.services.chime.model.ListUsersRequest;
import com.amazonaws.services.chime.model.ListUsersResult;
import com.amazonaws.services.identitymanagement.AmazonIdentityManagement;
import com.amazonaws.services.identitymanagement.AmazonIdentityManagementClientBuilder;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.Bucket;
import com.amazonaws.services.sns.AmazonSNS;
import com.amazonaws.services.sns.AmazonSNSClient;
import com.amazonaws.services.sns.AmazonSNSClientBuilder;
import com.amazonaws.services.sns.model.PublishRequest;
import com.amazonaws.services.sns.model.PublishResult;
public class snsTpic {
public static void main(String[] args)throws IOException {
AWSCredentials credentials = null;
try {
//credentials = new ProfileCredentialsProvider().getCredentials();
credentials = new BasicAWSCredentials("--", "--");
} catch (Exception e) {
throw new AmazonClientException(
"Cannot load the credentials from the credential profiles file. " +
"Please make sure that your credentials file is at the correct " +
"location (~/.aws/credentials), and is in valid format.",
e);
}
AmazonSNS snsClient = AmazonSNSClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(credentials)).build();
try {
System.out.println("Publishing my First SNS topic");
final String msg = "If you receive this message, publishing a message to an Amazon SNS topic works.";
final PublishRequest publishRequest = new PublishRequest("arn:aws:sns:us-east-2:459951688216:new_order", msg);
final PublishResult publishResponse = snsClient.publish(publishRequest);
// Print the MessageId of the message.
System.out.println("MessageId: " + publishResponse.getMessageId());
} catch (Exception e){
throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " +
"Please make sure that your credentials file is at the correct " +
"location (~/.aws/credentials), and is in valid format.",
e);
}
}
}
Вот вывод. У меня жестко закодированный доступ и секретный ключ в коде.
"C:\Program Files\Java\jdk-12\bin\java.exe" -javaagent:C:\Users\kp250041\Desktop\USA\ideaIC-2018.3.5.win\lib\idea_rt.jar=52391:C:\Users\kp250041\Desktop\USA\ideaIC-2018.3.5.win\bin -Dfile.encoding=UTF-8 -classpath "C:\Users\kp250041\Desktop\My Tools\aws-java-sdk-1.11.440\aws-java-sdk-1.11.440\lib\aws-java-sdk-1.11.440.jar;C:\Users\kp250041\Desktop\My Tools\commons-logging-1.2-bin\commons-logging-1.2\commons-logging-1.2.jar;C:\Users\kp250041\Desktop\Germany\AWSConnector\out\production\AWSConnector" com.example.publish.snsTpic
Exception in thread "main" java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper
at com.amazonaws.internal.config.InternalConfig.<clinit>(InternalConfig.java:43)
at com.amazonaws.internal.config.InternalConfig$Factory.<clinit>(InternalConfig.java:336)
at com.amazonaws.util.VersionInfoUtils.userAgent(VersionInfoUtils.java:142)
at com.amazonaws.util.VersionInfoUtils.initializeUserAgent(VersionInfoUtils.java:137)
at com.amazonaws.util.VersionInfoUtils.getUserAgent(VersionInfoUtils.java:100)
at com.amazonaws.ClientConfiguration.<clinit>(ClientConfiguration.java:70)
at com.amazonaws.ClientConfigurationFactory.getDefaultConfig(ClientConfigurationFactory.java:46)
at com.amazonaws.ClientConfigurationFactory.getConfig(ClientConfigurationFactory.java:36)
at com.amazonaws.client.builder.AwsClientBuilder.resolveClientConfiguration(AwsClientBuilder.java:167)
at com.amazonaws.client.builder.AwsClientBuilder.access$000(AwsClientBuilder.java:54)
at com.amazonaws.client.builder.AwsClientBuilder$SyncBuilderParams.<init>(AwsClientBuilder.java:478)
at com.amazonaws.client.builder.AwsClientBuilder.getSyncClientParams(AwsClientBuilder.java:419)
at com.amazonaws.client.builder.AwsSyncClientBuilder.build(AwsSyncClientBuilder.java:46)
at com.example.publish.snsTpic.main(snsTpic.java:42)
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.ObjectMapper
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 14 more
Процесс завершен с кодом выхода 1
Если кто-либо опубликовал Сообщение SNS с использованием Java SDK, поделитесь подробностями или помощью. Большое вам спасибо.