Sending SMS messages with Amazon SNS and Paws

Paws is a great way to access AWS services in Perl.  Here’s how you can send an SMS:

use Paws;
my $paws = Paws->service('SNS');
$paws->Publish(
   Message => "test",
   PhoneNumber => "+1XXXXXXXXXX",
);

If you get an error message saying

Invalid parameter: PhoneNumber Reason: +1XXXXXXXXXX is not valid to publish to

This may just mean that you aren’t connecting to the right endpoint, as SMS sending through SNS is only available in 6 regions at the time of this writing.  If your default region isn’t one of those, you can specify your region for this Paws instance like so:

use Paws;
my $paws = Paws->service('SNS', region => 'us-west-2');
$paws->Publish(
   Message => "test",
   PhoneNumber => "+1XXXXXXXXXX",
);

Leave a Reply

Your email address will not be published. Required fields are marked *