I am working on an app on AWS that needs to send text messages to customers. At times, the app just needs to send a single text message (AWS Transactional SMS may help here), at times it may need to text different groups of people (AWS doesn't seem to have a solution for this use case). It all depends on what the user is doing on the app.
I have explored the possibility of using SNS, but it requires users to be subscribed to a topic, which doesn't work for my use case. I have explored the possibility of using AWS Pinpoint, but it also doesn't seem to apply to my use case. I could use Twilio, but I would prefer to stay within AWS (Additionally, Twilio runs on AWS)
What is the best way to send text messages in the USA through AWS that doesn't require subscription to a topic?
If someone seeking for the answer of this Qn:
You can send SMS in 2 ways in AWS SNS.
Subscribe to a topic that is created in AWS SNS and send sms to all those numbers who had the subscription
Send SMS directly to a mobile number
What you need is the 2nd one.
I will demonstrate here how to do that with Ruby language.
Install the gem aws sns:
gem install aws-sdk-sns
require 'aws-sdk-sns'
1.Set SNS client
#sns_client = Aws::SNS::Client.new(
region: ENV['AWS_SNS_REGION'],
access_key_id: ENV['AWS_SNS_ACCESS_KEY'],
secret_access_key: ENV['AWS_SNS_SECRET_KEY']
)
2.Set SNS client attributes
#sns_client.set_sms_attributes({
attributes: {
'DefaultSenderID' => SENDER_ID,
'DefaultSMSType' => SMS_TYPE
}
})
3.Publish SMS
otp = (1000..9999).to_a.sample
#sns_client.publish({
phone_number: #mobile_no,
message: "#{OTM_MSG} #{otp}"
})
thats it!
OTM_MSG: ‘Your message comes here’
SMS_TYPE : ‘Transactional’ or ‘Promotional’
If you want to send OTP / bank transactions, then it is ‘Transactional’. Else if you want to send some promotional sms of your product then it is ‘Promotional’
SENDER_ID: is the sender id that you have already registered if you want to use your own sender id.
If you don't have sender id skip the step 2 - Set SNS client attributes
AWS_SNS_REGION, AWS_SNS_ACCESS_KEY, AWS_SNS_SECRET_KEY - are the credentials of your AWS account from where you would like to use SNS.
See the AWS documentation for this here:
https://docs.aws.amazon.com/sns/latest/dg/sms_publish-to-phone.html
It also provides code for Java language.
If you want to know more I have written an article here:
https://railsdrop.com/2021/03/04/aws-sns-how-to-send-sms/
Use the Publish action from the SNS service to send a text to a single phone without a topic. You could repeatedly call Publish to send texts to multiple phones.
https://docs.aws.amazon.com/sns/latest/dg/sms_publish-to-phone.html
Use the CreateTopic, Subscribe, and Publish actions from the SNS service to send a text to a multiple phones at once (uses a Topic).
https://docs.aws.amazon.com/sns/latest/dg/sms_publish-to-topic.html
Related
I live in India and I have this requirement where I need to change the default sender Id of text messages sent via AWS SNS to the one that is registered for our organization with TRAI. We are trying to send SMS text messages to customers with Indian mobile numbers. I tried passing TemplateID and EntityId that was issued to us by our provider on the AWS console to manually test things out by unfortunately, whenever I receive text message on my mobile, the sender name still shows a random number assigned by AWS and not the sender id that I configured. I also made sure that the template message approved by TRAI is exactly the same but it did not work either. There are no error logs on AWS either because the message was successfully delivered. Its just that the sender id is not the one that I had configured it to be.
Any help on this topic would be much appreciated. Thanks in advance!
P.S. We registered our template on JIO which is a Telecom provider here in India.
You can't use AWS SNS for this. You have to use AWS Pinpoint if you want to use your specific number. With Pinpoint you can also use short-codes and long-codes and can also configure your messages to be promotional or transactional. You can set your sender id in AWS pinpoint as well. Check the documentation below on how to do that.
https://docs.aws.amazon.com/pinpoint/latest/userguide/channels-sms-awssupport-sender-id.html
It doesn't matter if you have any registration with any telco providers as AWS will use it's own infra to send the messages. So you either have to use 100% AWS solution or 100% telco provider services. You can't mix and match both for SMS sending use-case.
UPDATE:
Well SNS and Pinpoint are 2 different services for 2 different use cases. SNS is only for "notifications" and Pinpoint is like a communication service.
As far as sender-id in SNS is concerned, some countries require it as a hard requirement. You can read more about it in the documentation below:
https://docs.aws.amazon.com/sns/latest/dg/channels-sms-awssupport-sender-id.html
AWS SNS does support using sender IDs together with template and entity IDs for targeting India. If you follow the instructions at https://docs.aws.amazon.com/sns/latest/dg/channels-sms-senderid-india.html, you'll be able to do this.
I know that Amazon Pinpoint enables 2-way SMS, but I was wondering whether it was possible to save the message that the client sends. I'm finding myself going down the AWS rabbit-hole a bit, but I was wondering if anyone has any recommendations as to what AWS services could hold onto response data.
Just to clarify, I understand that Pinpoint allows us to return automated messages when the client passes a keyword. I am also aware that we can create user segments to save user attributes, I am moreso inquiring whether there is a way to stream user responses (that are not keywords) to another service or topic. Thank you!
An overview of Amazon Pinpoint two-way messaging can be summarized as per the above sample architecture.
You can capture the incoming messages from your users using the SNS topic you would have created when activating Pinpoint two-way messaging i.e When your users reply to your SMS message using the long code number, Amazon Pinpoint sends a JSON payload to the Amazon SNS topic that you designated. As a developer you handle these incoming messages by adding subscriptions to this SNS topic. The supported subscriptions include SQS, Lambda, email, HTTPS endpoint or SMS.
A sample JSON payload that your SNS topic subscriptions would receive would resemble the following :
{
"originationNumber":"+27155550000",
"destinationNumber":"+2722255511111",
"messageKeyword":"START",
"messageBody":"Hello World from Amazon Pinpoint",
"inboundMessageId":"cae173d2-66b9-564c-8309-66b9",
"previousPublishedMessageId":"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
}
Hope this Helps!
Is there any way to publish a topic from Amazon SNS to multiple mobiles with Baidu cloud service?
Currently, when publish a message from SNS to baidu, I need specify EndpointArn which created with userid and channelid information. These information represent a mobile device.
==> I only publish from SNS to a specific mobile device represented by userid and channelid.
But I need publish a topic from SNS to multiple mobile devices which registered the topic.
I tried: smart phone register a topic (example: hello) to Baidu then SNS publish the same topic (hello) to Baidu. But the smartphone COULD NOT receive the topic message from SNS.
Anybody know how to make it work?
I just faced this problem, but finally find out it is required to set the following three message attributes for it to work:
AWS.SNS.MOBILE.BAIDU.DeployStatus
AWS.SNS.MOBILE.BAIDU.MessageType
AWS.SNS.MOBILE.BAIDU.MessageKey
Here is the reference:
https://docs.amazonaws.cn/sns/latest/dg/SNSMobilePushBaiduPublish.html
Our apps are being developed for both Android and iOS. We are using AWS SNS Mobile Push to push messages to both GCM and APNS. The back end is PHP and so it uses the AWS PHP SDK.
Until now, our system has been saving 1 Endpoint ARN per user. We then broadcast a Mobile Push message directly to this Endpoint ARN.
The question:
It would be strange if a user were logged into our app on multiple devices and did not receive push notifications on all of them. So - we're going to have to change something.
How, in AWS Mobile Push, is the concept of 'one user, multiple devices (and potentially multiple platforms) handled?
Does our system have to maintain a one-to-many association of user-to-EndpointARNs (i.e. start saving multiple EndpointARNs per user so that we may push messages to all of them sequentially)?
Or should I be looking into the 'Topics' concept that Mobile Push provides (I'm confused here - do some people use one topic per user, and then push messages to the topic itself?)..
Lastly - I guess as a bonus question - is it normal for people using the PHP AWS SDK to include both APNS and GCM attributes in the Message payload array? We haven't been keeping track of 'which type of device each user uses'. We've just been saving an Endpoint ARN per user. And I guess the thought was to just cover all our platform bases (APNS, APNS_SANDBOX, GCM) when we're pushing a message to an endpoint.
I've been doing a lot of searching on the 'one user with multiple devices' topic re: Mobile Push with AWS SNS, and really the results have been quite unhelpful.
Help please :(
Thanks!
Once you send SNS Push message , you will get success or failure reason.
Could you please check your logs and share to identify exact issue.
Cloudwatch :
SNS publishes Cloudwatch metrics for number of messages published, number of successful notifications, number of failed notifications and size of data published. Metrics are available on per application basis. You can access Cloudwatch metrics via AWS Management Console or CloudWatch APIs.
Direct addressing:
Direct addressing allows you to deliver notifications directly to a single endpoint, rather than sending identical messages to all subscribers of a topic. This is useful if you want to deliver precisely targeted messages to each recipient. When you register device tokens with SNS, SNS creates an endpoint that corresponds to the token. You can publish to the token endpoint just as you would publish to a topic. You can direct publish either the text of your notification, or a platform-specific payload that takes advantage of platform-specific features such as updating the badge count of your app. Direct addressing is currently only available for push notifications endpoints.
Official documentation, "When a topic is created, Amazon SNS will assign a unique ARN (Amazon Resource Name) to the topic.
https://aws.amazon.com/sns/faqs/
I have a solution for this issue as you already know ARN is associated with single device token so you must be manage it own your own to send push to same user with multiple device.
My approach is to create 2 table in mysql or whatever database you are using
1. For APNS or, APNS_SANDBOX having details like user_id(local), device token, endpoint ARN, status etc (EG : sns_apns)
2. Same for GCM or BAIDU you have to create a table having user details with endpoint ARN(EG : sns_gcm)
Now every time when you send push to a particular user just write a code something like this
Switch($platform) {
case 'APNS':
case 'APNS_SANDBOX':
Select all users from sns_apns by login id.
Create a message and send it to all users having same user id
case 'GCM':
Select all users from sns_gcm by login id.
Create a message and send it to all users having same user id
}
I haven't tried this but to solve your problem I would keep a map of the user's cognito userID and corresponding endpoint ARN for each major app defining transaction done by the user. If the endpoint already exist then no need to save it. But if for this userID another endpoint ARN is notice then save, update, add or associate this new endpointARN with userID in DynamoDB as a #Document attribute. Then at anytime just broadcast to all endpointARN associated to the userID in DynamoDB.
The mysampleapp mobile hub example codes are useful for quick manipulation. For android:
Get the endpointARN in app like this:
PushManager pushManager;
String userDeviceEndPoint;
pushManager = AWSMobileClient.defaultMobileClient().getPushManager();
userDeviceEndPoint = pushManager.getEndpointArn();
You can update DynamoDB using the update save behaviour to ignore if an already existing endpoint is noticed for the user:
DynamoDBMapper mapper = new DynamoDBMapper(ddbClient, new DynamoDBMapperConfig(DynamoDBMapperConfig.SaveBehavior.UPDATE_SKIP_NULL_ATTRIBUTES));
Not sure how to do this in PHP though. Hope this idea helps.
In my JAVA application, I'm using Amazon SNS to send emails to customer; Once I subscribe one customer(email id) into my SNS Topic; It is asking the customer to confirm the subscription to receive the emails;
Is there any way to confirm the subscription in our application itself(without cusstomer's help)?
No, it is not possible.
The entire point of the confirmation step is to force the end user to confirm the subscription so that SNS cannot be used as a spamming mechanism. If SNS allowed the application developer to confirm subscriptions without access to the endpoint token, then you could confirm anyone's email address.
Note however, that SNS could technically implement a feature which would allow the email owner to confirm subscriptions for your account, so that if your application will be subscribing and unsubscribing an email address from lots of topics, they wouldn't have to confirm each one. Sadly, that feature currently doesn't exist.
One other possibility which would actually give you what you need is if SNS allowed you to send emails from your SES account and use your SES trust level. Again, this feature doesn't exist currently.
Until the SNS team delivers a feature which allows this use case, if you need to deliver to customers, you could allow SNS to do the fanout for you to HTTP or SQS queues, then deliver emails from those notification using SES.
Just as a suggestion, you can use Amazon Pinpoint to send emails to non-verified addresses (after moving out of sandbox). See https://docs.aws.amazon.com/pinpoint/latest/userguide/channels-email-setup-production-access.html