import boto3
# Create an SNS client
client = boto3.client(
"sns",
aws_access_key_id="YOUR ACCES KEY",
aws_secret_access_key="YOUR SECRET KEY",
region_name="us-east-1"
)
# Send your sms message.
client.publish(
PhoneNumber ="+12223334444",
Message="Hello World!"
)
i have already added my number in aws SNS console ,and only to that number i can send message
if i want to send message to any other number, how can i send the messages to other phone numbers using pyhton and how can i add phone number in aws console using python
There are two ways to send messages in Amazon SNS:
Send directly to a phone number by using client.publish(PhoneNumber="..."), or
Send a message to an Amazon SNS Topic, and the message will be sent to all Subscribers of that topic
Subscriptions can be via email, SMS, HTTP Endpoint, etc.
Your code is using the first method, so it is sending the message to a specific phone number. If you actually want to send the message to multiple recipients, then create an SNS Topic, subscribe the recipients and then send the message to the SNS Topic using: client.publish(TopicArn="...")
Related
I am sending SMS to Indian mobile numbers using SNS production account(not configured SenderId) in ap-south-1 region with boto3 api using below code
sns = boto3.client('sns',region_name='us-east-1')
number = "+91"+user_mobile_number
content = sns.publish(PhoneNumber=number, Message="Dear Customer, Use this to verify your mobile:"+verification_code+"")
SMS logs shows success status for all but only first SMS is delivered correctly and all other SMS are not delivered.
SMS delivered correctly at random times.
As per aws documentation, to send SMS to India using AWS SNS suggests to register with TRAI,
Trying to debug but cannot find why the SMS are not delivered, is there any restrictions in sending SMS to indian numbers ?
Is it mandatory to register TRAI to send SMS to Indian number?
Hello is there an Amazon SES API (or some kind of webhook) which allows us to see the list of bounced emails?
I know SNS exists but that costs extra.
From Amazon SES notifications sent by email - Amazon Simple Email Service:
Amazon SES can send you email when you receive bounces and complaints by using a process called email feedback forwarding.
In order to send email using Amazon SES, you must configure it to send bounce and complaint notifications by using one of the following methods:
By enabling email feedback forwarding
By sending notifications to an Amazon SNS topic
By publishing event notifications
So, if you don't want to use an Amazon SNS topic (which is very low cost!), you could have them sent via email.
I configured my SES notifications sent to SNS service. When I send email from SES using python, SNS send me notifications about email is sent & delivered with timestamps. But at that time I didn't receive email at all while Aws SES notifies me it's delivered. I received the email few minutes after that. Anyone can explain how these timestamps works?
The timestamps are when SES successfully sent the email message but those timestamps have nothing to do with how long it takes your mail client to check the mail server for new messages and download the messages to the client, or even how long your mail server takes to route the message to the right inbox (although that should be very fast).
Consider the case where your may client is configured to check for new emails every 5 minutes:
Minute 1: SES successfully delivers the email.
Minute 2: SNS delivers the notification to you with Timestamp 1.
Minute 5: Your email client checks the mail server and detects there is a new message, and downloads it.
You will see the message in your email client at Minute 5 although SES delivered it at Minute 1.
Hope this helps.
I have a contact us service which is triggered by users from a website.
Whenever user sends message, an email is sent to admin to notify about new contact. This email is in the form a json given below,
Is there a way to have it as a formatted email? I have figured out one method that is write a lambda to trigger SES. Is there a better method?
When SNS sends an email, it sends the entire notification and not just the message attribute.
You cannot format message or only send some of the attributes.
Your message is in JSON format, have you tried the subscription protocol "Email" instead of "Email-JSON"? It should give the same result but just in clear text. I dont know if that will help your situation.
An alternative would be to send the notifications to Lambda which can then send a formattet email via SES. You can either send the messages directly to Lambda, or via a SQS for resilience (see this discussion).
Can we send a SMS to a mobile number through amazon service? I need to send a plain message and not notifications.
No.
Amazon Simple Notification Service (SNS) can't send SMS messages to recipients who have not opted-in to receive topic notifications.
The SMS capability in SNS is limited to users who respond affirmatively to the initial message requesting that they confirm their subscription to a topic -- for notifications.