来自Java的AWS SNS调用

时间:2017-08-04 08:00:30

标签: java amazon-web-services amazon-sns

我正在创建一个Lambda(Java),如果我的值超过特定的阈值限制,我需要从我的Java代码执行AWS SNS主题调用(Email)。我已经创建了一个发布主题,我的主题是ARN用于订阅。 到目前为止的代码:

if(list.get(0)<=25000) {
        System.out.println("Minimum" + list.get(0));
        //call SNS to send Alert//


    }else {
        System.out.println("Maximum" + list.get(list.size()-1));
    }

////我的SNS实用程序//

public static void main(String[] args) {
    AmazonSNSClient snsClient = new AmazonSNSClient();
    String message = "My SMS message";
    Map<String, MessageAttributeValue> smsAttributes = 
            new HashMap<String, MessageAttributeValue>();
   String topicArn = "<my_topic_arn>";
     sendSMSMessageToTopic(snsClient, topicArn, message, smsAttributes);
}
public static void sendSMSMessageToTopic(AmazonSNSClient snsClient, String topicArn, 
        String message, Map<String, MessageAttributeValue> smsAttributes) {
        PublishResult result = snsClient.publish(new PublishRequest()
                        .withTopicArn(topicArn)
                        .withMessage(message)
                        .withMessageAttributes(smsAttributes));
        System.out.println(result);
}

问题:

  1. 如何在我的第一个if条件下调用SNS实用程序?

1 个答案:

答案 0 :(得分:0)

您可以拨打publish() method。有几个版本,例如:

public PublishResult publish(String topicArn,
                             String message,
                             String subject)