Search code examples
rubyamazon-sns

Amazon SNS with ruby, simple sms message


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]


Solution

  • 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...>