我正在使用以下代码:
AmazonSNSClient snsClient = new AmazonSNSClient(credentials);
snsClient.setRegion(Region.getRegion(Regions.SA_EAST_1));
String msg = "My text published to SNS topic with email endpoint";
String arn = "XXXXX";
PublishRequest publishRequest = new PublishRequest("topicARN here",msg);
PublishResult publishResult = snsClient.publish(publishRequest);
但是我正在跟随错误。
“ InvalidParameterException:状态代码:400,AWS服务:AmazonSNS,
AWS请求ID:446fef49-4eba-5484-ba4c-bf82682cdc46,AWS错误代码:
InvalidParameter,AWS错误消息:无效参数:TopicArn“
谁能帮我这个?
最佳答案
我认为您的主题ARN尚不存在。检查它是否存在或显式创建它。
这是您的HelloWorldSNS
:
public class HelloWorldSNS {
public static void main(String[] args) throws Exception {
AmazonSNSClient client = Region.getRegion(Regions.EU_CENTRAL_1).createClient(AmazonSNSClient.class, null,
null);
CreateTopicResult createTopic = client.createTopic("myTopic");
SubscribeResult subscribe = client.subscribe(createTopic.getTopicArn(), "email", "[email protected]");
PublishRequest publishRequest = new PublishRequest(createTopic.getTopicArn(), "Test message");
client.publish(publishRequest);
}
}