5/21投稿ーーーーーー
y_waiwaiさんからいただいたアドバイス通り実行してみたところ
以下のエラーが表示されました。
[Sun May 20 23:29:28.344157 2018] [:error] [pid 25122] [client 106.181.135.135:51420] PHP Fatal error: Uncaught exception 'Aws\Exception\CredentialsException' with message 'Error retrieving credentials from the instance profile metadata server. (Client error: `GET http://169.254.169.254/latest/meta-data/iam/security-credentials/` resulted in a `404 Not Found` response:\n<?xml version="1.0" encoding="iso-8859-1"?>\n<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\n "htt (truncated...)\n)' in /var/www/html/vendor/aws/aws-sdk-php/src/Credentials/InstanceProfileProvider.php:88\nStack trace:\n#0 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(203): Aws\Credentials\InstanceProfileProvider->Aws\Credentials\{closure}(Array)\n#1 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(2, Array, Array)\n#2 /var/www/html/vendor/guzzlehttp/promises/src/TaskQueue.php(47): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}()\n#3 /var/www/html/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(98): GuzzleHttp\Promise\TaskQueue->run()\n#4 /var/www in /var/www/html/vendor/aws/aws-sdk-php/src/Credentials/InstanceProfileProvider.php on line 88
credentialsのファイル(認証情報を記載したファイル)を取得中にエラーになっているようなことが書いてあります。
credentialsファイルはhome/ec2-user/.awsの配下にあります。
エラーメッセージで検索したところ以下のリンクを見つけて、コメントの通り
AWS CLIをインストール > $ aws configure > シークレットキーなどの入力もしましたが、
結果は同じでした。
認証情報は作成したIAMユーザーの認証情報だが、実行ユーザーはec2-userである点が、
怪しいかもと思っているのですが、IAMユーザーを実行ユーザーにする方法がわかりません。。。
ちなみに、testmail.phpをコマンドで実行するとメール送信は成功します。
[ec2-user@ip-172-31-39-44 html]$ php testmail.php Email sent! Message ID: 010101638168d54e-2db33562-1e58-46cd-8be8-e24da6349e25-000000
5/20投稿ーーーーーー
プログラミング勉強中の者です。
Amazon SESでメール送信を実装しようとしています。
AWSのチュートリアルに沿って、もろもろ設定を終え、
ターミナルでphpファイル(testmail.php)を実行し送信成功するところまでは出来たのですが、
ブラウザで実行するとエラーが出てしまいます。
エラーログをみると権限の問題のようなのですが、権限をどのように設定すれば良いのかわかりません。。。
home ディレクトリ以下の権限は以下の通りです。
drwxrwxrwx 3 root root 4096 4月 3 23:05 home drwx------ 7 ec2-user ec2-user 4096 5月 9 15:56 ec2-user drwxrwxr-x 10 ec2-user ec2-user 4096 5月 20 15:57 vendor -rwxrwxr-x 1 ec2-user ec2-user 178 5月 9 15:57 autoload.php drwxrwxr-x 3 ec2-user ec2-user 4096 5月 9 15:57 aws drwxrwxr-x 2 ec2-user ec2-user 4096 5月 9 15:57 bin drwxrwxr-x 2 ec2-user ec2-user 4096 5月 9 15:57 composer drwxrwxr-x 3 ec2-user ec2-user 4096 5月 1 15:39 guzzle drwxrwxr-x 5 ec2-user ec2-user 4096 5月 9 15:57 guzzlehttp drwxrwxr-x 3 ec2-user ec2-user 4096 5月 9 15:57 mtdowling drwxrwxr-x 3 ec2-user ec2-user 4096 5月 9 15:57 psr drwxrwxr-x 3 ec2-user ec2-user 4096 5月 1 15:39 symfony
testmail.phpの権限(var/www/html/testmail.php)
-rw-r--r-- 1 ec2-user apache 2468 5月 9 17:04 testmail.php
エラーログ
[Sun May 20 16:29:28.411700 2018] [:error] [pid 22602] [client 106.181.133.216:62905] PHP Warning: require(../../../home/ec2-user/vendor/autoload.php): failed to open stream: Permission denied in /var/www/html/testmail.php on line 33 [Sun May 20 16:29:28.411745 2018] [:error] [pid 22602] [client 106.181.133.216:62905] PHP Fatal error: require(): Failed opening required '../../../home/ec2-user/vendor/autoload.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/testmail.php on line 33
testmail.php
<?php // Replace path_to_sdk_inclusion with the path to the SDK as described in // http://docs.aws.amazon.com/aws-sdk-php/v3/guide/getting-started/basic-usage.html define('REQUIRED_FILE','../../../home/ec2-user/vendor/autoload.php'); // Replace sender@example.com with your "From" address. // This address must be verified with Amazon SES. define('SENDER', 'sample@sample.com'); // Replace recipient@example.com with a "To" address. If your account // is still in the sandbox, this address must be verified. define('RECIPIENT', 'sample@sample.com'); // Specify a configuration set. If you do not want to use a configuration // set, comment the following variable, and the // 'ConfigurationSetName' => CONFIGSET argument below. define('CONFIGSET','ConfigSet'); // Replace us-west-2 with the AWS Region you're using for Amazon SES. define('REGION','us-west-2'); define('SUBJECT','Amazon SES test (AWS SDK for PHP)'); define('HTMLBODY','<h1>AWS Amazon Simple Email Service Test Email</h1>'. '<p>This email was sent with <a href="https://aws.amazon.com/ses/">'. 'Amazon SES</a> using the <a href="https://aws.amazon.com/sdk-for-php/">'. 'AWS SDK for PHP</a>.</p>'); define('TEXTBODY','This email was send with Amazon SES using the AWS SDK for PHP.'.'http://owalive.fun?p=1'); define('CHARSET','UTF-8'); require REQUIRED_FILE; use Aws\Ses\SesClient; use Aws\Ses\Exception\SesException; $client = SesClient::factory(array( 'version'=> 'latest', 'region' => REGION )); try { $result = $client->sendEmail([ 'Destination' => [ 'ToAddresses' => [ RECIPIENT, ], ], 'Message' => [ 'Body' => [ /*'Html' => [ 'Charset' => CHARSET, 'Data' => HTMLBODY, ],*/ 'Text' => [ 'Charset' => CHARSET, 'Data' => TEXTBODY, ], ], 'Subject' => [ 'Charset' => CHARSET, 'Data' => SUBJECT, ], ], 'Source' => SENDER, // If you are not using a configuration set, comment or delete the // following line // 'ConfigurationSetName' => CONFIGSET, ]); $messageId = $result->get('MessageId'); echo("Email sent! Message ID: $messageId"."\n"); } catch (SesException $error) { echo("The email was not sent. Error message: ".$error->getAwsErrorMessage()."\n"); } ?>
2日調べ、home/ec2-user/vendor以下をvar/www/html/配下に移すなどもしたのですが、
解決出来ず、アドバイスをいただけないでしょうか。
上記以外に必要な情報がございましたらご指示ください。
よろしくお願いいたします。

回答4件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/21 11:28
2018/05/22 01:07 編集
2018/05/23 03:35
2018/05/23 05:16
2018/05/23 06:33
2018/05/23 06:37 編集
2018/05/23 11:24
2018/05/24 03:12 編集
2018/05/24 02:08
2018/05/24 03:20