2016-12-14 73 views
1

我使用下面的代碼:我不能發佈SNS信息如電子郵件

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錯誤代碼: 無效參數,AWS錯誤消息:無效參數:TopicArn」

任何人都可以幫助我嗎?

回答

1

我認爲你的主題ARN尚不存在。檢查它是否存在或明確創建它。

Here'a 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); 
    } 
}