Unable to send an email on demand using AWS SesClient
I am trying to send an email for a password recovery on demand. That is I receive an http request in my API and I call sendBulkTemplatedEmail() through a function called send_email()
.
Here is the thing:
php finename.php
, the email is sent successfully.sendBulkTemplatedEmailfunction
simply freezes. send_email($destination_email, $type){
/.../
try {
$SesClient->sendBulkTemplatedEmail($data_to_attach);
$messageId = 1;
echo("Email sent! Message ID: $messageId"."\n");
return true;
} catch (AwsException $e) {
/..../
}
}
I suspect that a different user is being used in each case.
When you run php
from the command-line, it is running as your logged-in user (ec2-user
?). However, when it is triggered via a request, it is running as a different user (apache
?), and that user does not have credentials in their ~/.aws/credentials
file.
This can be fixed by copying the credentials to the other user's ~/.aws
directory.