amazon-web-servicesamazon-sns

Why are my SMS messages sent via Amazon SNS not being received by Indian phone numbers?


I am trying to send text SMS using Amazon SNS in my Springboot application.

This is the configuration class:

@Configuration
@ConfigurationProperties("aws")
public class AwsConfig {

    private String accessKeyId;
    private String secretAccessKey;

    public String getAccessKeyId() {
        return accessKeyId;
    }

    public void setAccessKeyId(String accessKeyId) {
        this.accessKeyId = accessKeyId;
    }

    public String getSecretAccessKey() {
        return secretAccessKey;
    }

    public void setSecretAccessKey(String secretAccessKey) {
        this.secretAccessKey = secretAccessKey;
    }

    public AWSStaticCredentialsProvider awsCredentials() {
        BasicAWSCredentials credentials = new BasicAWSCredentials(accessKeyId, secretAccessKey );
        return new AWSStaticCredentialsProvider(credentials);
    }

    @Bean
    public AmazonSimpleEmailService getAmazonSimpleEmailService() {
        return AmazonSimpleEmailServiceClientBuilder.standard().withCredentials(awsCredentials())
                .withRegion("us-east-1").build();
    }
    
    @Bean
    public AmazonSNS getAmazonSNS() {
        return AmazonSNSClientBuilder.standard().withCredentials(awsCredentials())
                .withRegion("us-east-1").build();
    }
}

This is the class to send messages:

@Service
public class SmsSendingServiceImpl {

    @Autowired
    private AmazonSNS amazonSNS;
    
    public void sendSMS()
    {
        Map<String, MessageAttributeValue> smsAttributes = new HashMap<String, MessageAttributeValue>();
         smsAttributes.put("AWS.SNS.SMS.SenderID", new MessageAttributeValue()
                    .withStringValue("SENDER") 
                    .withDataType("String"));
         smsAttributes.put("AWS.SNS.SMS.SMSType", new MessageAttributeValue()
                    .withStringValue("Transactional")
                    .withDataType("String"));
         
         try {
                PublishResult result = amazonSNS.publish(new PublishRequest()
                        .withMessage("This is a test sms.")
                        .withPhoneNumber("+91-**********").withMessageAttributes(smsAttributes));
                
                System.out.println("Messsage Sent. "+result.getMessageId());

            } catch (Exception ex) {
                ex.printStackTrace();
            }
             
    }
}

On calling sendSMS() I do get the Message Sent. message in the console output, but no SMS is being received on the phone number mentioned.

I have tried several different phone numbers for this. None of them are receiving any messages.

It might be worth mentioning that all these numbers are Indian.

Can someone please point out what might be the cause for this?

This is the YouTube video I'm referring to.


Solution

  • The issue you are facing is that India is a country that has special requirements for using a non-numeric sender ID for SMS messages.


    Based on Supported Regions and countries documentation for SNS:

    Country or region       ISO code        Supports sender IDs     Supports two-way SMS (Amazon Pinpoint only)
    India                   IN              Yes3                    Yes
    

    Note that the Supports sender IDs column for India is marked as Yes3.

    Notes section states:

    1. Senders are required to use a pre-registered alphabetic sender ID. Additional registration steps are required. For more information, see Special requirements for sending SMS messages to recipients in India.

    For your origination identity, you can either have origination numbers or sender IDs.

    In your case, you cannot opt to use origination numbers as Indian laws require the use of sender IDs instead.

    The opposite situation also exists as countries like Canada, China, and the United States require the use of origination numbers (read: U.S. product number comparison for different number types for the number you need to purchase & the SMS cost calculator).

    From AWS:

    This feature (origination numbers) does not apply when sending SMS to countries where local limitations, laws, or regulations require the use of Sender Ids in the place of origination numbers, for example India.

    Therefore, you must follow the Special requirements for sending SMS messages to recipients in India guide. This is what is meant by Additional registration steps are required above.


    Unfortunately, there is no workaround for local country laws that AWS apparently needs to abide by.

    That said, there may be domestic services that can "circumvent" AWS's legal restriction (as they are domestic/may have special contracts with telecoms etc.). If you don't want to/can't register a sender ID, other services may also be worth looking at.