I'm trying to send a simple sms from ruby directly to a phone number with the SNS service.
require 'aws-sdk'
sns = Aws::SNS::Client.new(region: 'my_region', access_key_id: 'my_id', secret_access_key: 'mykey')
sns.publish({phone_number: 'my_number', message: 'test message'})
but i get ArgumentError: unexpected value at params[:phone_number]
The following example using a fictional UK mobile phone number in E.164 format works for me, are you sure you're passing phone_number
in a string?
require 'aws-sdk'
sns = Aws::SNS::Client.new(...)
#=> #<Aws::SNS::Client>
sns.publish(phone_number: '+447911123456', message: 'test message')
#=> #<struct Aws::SNS::Types::PublishResponse...>
The simplest way to send an SMS with AWS (assuming the from number is one you own in AWS Pinpoint).
client = 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']
)
response = client.publish(
phone_number: "+1<your phone>",
message: "something something",
message_attributes: {
"AWS.SNS.SMS.SMSType" => {
data_type: "String",
string_value: "Promotional",
},
"AWS.MM.SMS.OriginationNumber" => {
data_type: "String",
string_value: "+1<AWS Pinpoint number>",
},
},
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With