Created
January 19, 2021 23:25
-
-
Save renatocron/e7d04f93176223e8ce58e3d46d8a3e15 to your computer and use it in GitHub Desktop.
Send SMS Transactional using Amazon::SNS (perl)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use Amazon::SNS; | |
use LWP::ConsoleLogger::Everywhere (); | |
my $message = 'test' . time; | |
my $phonenumber = '+55119000000'; | |
$ENV{AWS_SNS_KEY} = 'xxxxx'; | |
$ENV{AWS_SNS_SECRET} = 'yyy'; | |
$ENV{AWS_SNS_ENDPOINT} = ''; | |
my $sns = Amazon::SNS->new( | |
{ | |
'key' => $ENV{AWS_SNS_KEY}, | |
'secret' => $ENV{AWS_SNS_SECRET}, | |
} | |
); | |
$sns->service($ENV{AWS_SNS_ENDPOINT} || 'http://sns.us-east-1.amazonaws.com'); | |
my $r = $sns->dispatch( | |
{ | |
'Action' => 'Publish', | |
'Message' => $message, | |
'PhoneNumber' => $phonenumber, | |
'Attributes' => { | |
'MessageAttributes.entry.1.Name' => 'AWS.SNS.SMS.SMSType', | |
'MessageAttributes.entry.1.Value.StringValue' => 'Transactional', | |
'MessageAttributes.entry.1.Value.DataType' => 'String', | |
} | |
} | |
); | |
my $success = $r->{'PublishResult'}{'MessageId'}; | |
if (!$success) { | |
my $err = $sns->error; | |
#return $job->fail($r->error()); | |
} | |
print $success . "\n"; | |
#$log->update({sns_message_id => $success}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment