AWSのSNSでトピックを作成しておきます。
mkdir /opt/aws/aws-sdk-php
cd /opt/aws/aws-sdk-php
vim composer.json
---
{
"require": {
"aws/aws-sdk-php": "2.*"
}
}
---
curl -sS https://getcomposer.org/installer | php
php composer.phar installvim sns_alert.php
---
<?php
require '/opt/aws/aws-sdk-php/vendor/autoload.php';
use Aws\Sns\SnsClient;
// Create an array of configuration options
$config = array(
'key' => '****',
'secret' => '****',
'region' => 'ap-northeast-1'
);
$topic = '{作成したTopicのARN名}';
$client = SnsClient::factory($config);
$responce = null;
$messageId = null;
try
{
$responce = $client->publish(array('TopicArn'=>$topic, 'Subject'=>'Test', 'Message'=>'Test'));
$messageId = $responce->getPath('MessageId');
}
catch (Exception $e)
{
print_r($e->getMessage());
}
if (empty($responce) || empty($messageId)) {
# retry
try
{
$client->publish(array('TopicArn'=>$topic, 'Subject'=>'Test', 'Message'=>'Test'));
}
catch (Exception $e)
{
print_r($e->getMessage());
}
}
?>
---でSNSを使用できます。


