我使用以下代码:
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);
但我得到了ERROR。
“InvalidParameterException:Status Code:400,AWS Service:AmazonSNS, AWS请求ID:446fef49-4eba-5484-ba4c-bf82682cdc46,AWS错误代码: InvalidParameter,AWS错误消息:参数无效:TopicArn“
任何人都可以帮我吗?
答案 0 :(得分:1)
我认为您的主题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", "some@email.com");
PublishRequest publishRequest = new PublishRequest(createTopic.getTopicArn(), "Test message");
client.publish(publishRequest);
}
}