Prepping the Environment
1 2 3 4 5 6 7 8 9 10 11 12 |
root@ip:~# echo "export AWS_SHARED_CREDENTIALS_FILE=/root/.aws/credentials" >> /etc/apache2/envvars root@ip:~# chown -R www-data:www-data /root root@ip:~# service apache2 restart root@ip:~/.aws# cat credentials [default] aws_access_key_id = AKIZXZXZXZXZXXZZXQW aws_secret_access_key = jzv6v9v6a9S+aQWSA70DA6/JADA6A6A2GAW7 [project1] aws_access_key_id = ANOTHER_AWS_ACCESS_KEY_ID aws_secret_access_key = ANOTHER_AWS_SECRET_ACCESS_KEY |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
<?php require '/home/ubuntu/vendor/autoload.php'; use Aws\Sns\SnsClient; //use Aws\S3\S3Client; use Aws\Exception\AwsException; function formatNumber($number) { $formatted = preg_replace('~.*(\d{3})[^\d]{0,7}(\d{3})[^\d]{0,7}(\d{4}).*~', '+1$1$2$3', $number). "\n"; $formatted = trim($formatted, "\n\r "); if(preg_match("/^\+1[0-9]{10}$/", $formatted)) { print "valid: "; // $phone is valid print $number . " - > " . $formatted . "\r\n"; return $formatted; } else { print "not a phone: "; print $number . "\r\n"; return NULL; } } function sendSMS($number, $body) { $myvar = formatNumber($number); if (!is_null($myvar)) { $SnSclient = new SnsClient([ 'profile' => 'default', 'region' => 'us-west-2', 'version' => '2010-03-31' ]); $message = $body; //'This is being sent from AWS with sms.php in the public folder.'; $phone = $myvar; //'+12223334444'; try { $result = $SnSclient->publish([ 'Message' => $message, 'PhoneNumber' => $phone, ]); //var_dump($result); } catch (AwsException $e) { // output error message if fails echo ($e); error_log($e->getMessage()); } return true; } else { //invalid number return false; } } //sendSMS("+12223334444", "test"); ?> |