Search code examples
javaamazon-web-servicessmsamazon-snsaws-java-sdk

Aws SMS using java


I've done a code to send SMS to specific phone number using java which uses AWS-SNS API's it works fine but i just wanted to verify if the message has been delivered or not. for example : say if the mobile number is wrong or does not exist like +910000000000

below is my code

import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.sns.AmazonSNS;
import com.amazonaws.services.sns.AmazonSNSClient;
import com.amazonaws.services.sns.model.PublishRequest;

public class SMSClass {

    public static void main(String[] args) {
        
        //Used for authenticating to AWS
        BasicAWSCredentials awsCreds = new BasicAWSCredentials("Access_Key", "Secret_Access_Key");
        
        //Create SNS Client
        AmazonSNS snsClient = AmazonSNSClient
                .builder()
                .withRegion(Regions.AP_SOUTHEAST_2)
                .withCredentials(new AWSStaticCredentialsProvider(awsCreds))
                .build();
        
        String SMSMessage = "Sent using AWS SNS";
        String mobile = "+910000000000";//Enter your mobile number here
        
        snsClient.publish(new PublishRequest().withMessage(SMSMessage).withPhoneNumber(mobile));
        
        

    }

}

any help will be really helpful thanks in advance


Solution

  • You can use the Cloudwatch Logs service as mentioned in this AWS document.