I really want to publish a lambda subscriber to an SNS topic. It works in amazon console, but with php-sdk it does not. When I execute the php code and I look in CloudWatch, there's nothing (no response). Why my SNS did not work?
it is my code, but it does not working:
....
$credentials = new Credentials($access, $secret);
$this->aws_client = new SnsClient(
array(
'region' => 'us-east-1',
'version' => 'latest',//'version' => '2010-03-31',
'credentials' => $credentials
)
);
...
$message = "Hello H.";
$message_atr = array('String' => array('DataType' => 'String', 'StringValue' => $message));
$payload = array(
'TargetArn' => 'arn:aws:sns:us-east-1:****:mysns',
'Message' => $message,
'MessageAttributes' => $message_atr,
);
$this->aws_client->publish($payload);
Related
I am using amazon PHP SDK to try to send sms I am using following code:
<?php
require 'vendor/autoload.php';
$sdk = new Aws\Sns\SnsClient([
'region' => 'eu-west-1',
'version' => 'latest',
'credentials' => ['key' => 'xxx', 'secret' => 'xxx']
]);
$result = $sdk->publish([
'Message' => 'This is a test message.',
'PhoneNumber' => '+123456789',
'MessageAttributes' => ['AWS.SNS.SMS.SenderID' => [
'DataType' => 'String',
'StringValue' => 'testing sms'
]
]]);
print_r( $result );
My question is how do I get delivery Status back to an endpoint url HTTPS or HTTP?
like the sms got delivered or failed? any idea?
The only way to do this today is to leverage the CloudWatch API (e.g. https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_GetLogEvents.html) to read the logs delivered to your log groups
Currently I'm sending email through AWS SDK SES signature 3 and got an email from Amazon to upgrade it to SES signature version 4. But where to add signature in AWS SDK? below is the current code that is being used to send emails.
<?php
//SES
$SESCredentials = array(
'key' => awsSESAccessKey,
'secret' => awsSESSecretKey
);
$SESClient = new SesClient([
// 'profile' => 'default',
'version' => AWS_SDK_VERSION,
'region' => AWS_REGION,
'http' => [
'verify' => AWS_CERT_PATH
],
'credentials' => $SESCredentials
]);
$result = $SESClient->sendEmail([
'Destination' => [
'ToAddresses' => $recipient_emails
],
'ReplyToAddresses' => [$sender_email],
'Source' => $sender_email,
'Message' => [
'Body' => [
'Html' => [
'Charset' => $char_set,
'Data' => $html_body
]
],
'Subject' => [
'Charset' => $char_set,
'Data' => $subject,
]
]
]);
?>
You can use this package as it supports signature 4
https://github.com/daniel-zahariev/php-aws-ses
$signature_version = SimpleEmailService::REQUEST_SIGNATURE_V4;
$ses = new SimpleEmailService('AccessKey', 'SecretKey', $region_endpoint,
$trigger_error, $signature_version);
$m->addTo('Recipient Name <recipient#example.com>');
$m->setFrom('Sender <user#example.com>');
$m->setSubject('Hello, world!');
$m->setMessageFromString('This is the message body.');
$ses = new SimpleEmailService('AccessKey', 'SecretKey');
print_r($ses->sendEmail($m));
I'm trying to send an SMS through my PHP site using the AWS SDK. I use the code from Sending SMS with Amazon AWS services PHP.
require $_SERVER['DOCUMENT_ROOT'] . '/inc/aws/aws-autoloader.php';
error_reporting(E_ALL);
ini_set("display_errors", 1);
$params = array(
'credentials' => array(
'key' => 'abc',
'secret' => 'abc',
),
'region' => 'eu-west-1', // < your aws from SNS Topic region
'version' => 'latest'
);
$sns = new \Aws\Sns\SnsClient($params);
$args = array(
"SenderID" => "TestSender",
"SMSType" => "Transactional",
"Message" => "Sending SMS with PHP",
"PhoneNumber" => "+87654321"
);
$result = $sns->publish($args);
echo "<pre>";
var_dump($result);
echo "</pre>";
This is not working. I have tested with a lot of different SenderIDs and all messages are received from NOTICE.
However, when I send a message from the AWS console, the message is received with the correct SenderID. So I assume my code is wrong.
I found the solution. Set the args this way. It works!
$args = array(
'MessageAttributes' => [
'AWS.SNS.SMS.SenderID' => [
'DataType' => 'String',
'StringValue' => 'YourSenderName'
]
],
"SMSType" => "Transactional",
"PhoneNumber" => "+87654321",
"Message" => "Hello World!"
);
I am trying to send a sms to a particular number using aws sns using the following code but it requires a target/topic arn which is not applicable for me as I want to send sms to the numbers that I set in the params.
$client = SnsClient::factory([
'credentials' => [
'key' => "my key",
'secret' => "my secret"
],
'region' => "us-east-1",
'version' => "latest"
]);
$sent = $client->publish(
[
'Message' => 'This is the message',
'PhoneNumber' => '+91887******7'
]
);
I am not able to find the exact params for the publish object.
I had to update the aws php sdk (1). Then the following code works fine -
$sns = SnsClient::factory(array(
'credentials' => array(
'key' => 's3_key',
'secret' => 's3_secret'
),
'region' => Constants::$s3Region,
'version' => 'latest'
));
$msgattributes = [
'AWS.SNS.SMS.SenderID' => [
'DataType' => 'String',
'StringValue' => 'Klassroom',
],
'AWS.SNS.SMS.SMSType' => [
'DataType' => 'String',
'StringValue' => 'Transactional',
]
];
$payload = array(
'Message' => $message,
'PhoneNumber' => $number,
'MessageAttributes' => $msgattributes
);
$result=$sns->publish($payload);
From the Amazon SNS Publish() documentation for PHP:
TargetArn: If you don't specify a value for the TargetArn parameter, you must specify a value for the PhoneNumber or TopicArn parameters.
TopicArn: If you don't specify a value for the TopicArn parameter, you must specify a value for the PhoneNumber or TargetArn parameters.
PhoneNumber: If you don't specify a value for the PhoneNumber parameter, you must specify a value for the TargetArn or TopicArn parameters.
Therefore, provide a PhoneNumber instead of a Target/Topic.
Is there a way to verify email domain or send verification through API? I would like my client to confirm their email domain when they create an email campaign in my website.
I am using PHP AWS SDK v2. http://docs.aws.amazon.com/aws-sdk-php/v2/guide/service-ses.html
$mailbox_email = 'email#yourdomain.com';
$aws_client = \Aws\Common\Aws::factory(array(
'region' => 'eu-west-1',
'credentials' => array(
'key' => AWS_ACCESS,
'secret' => AWS_SECRET
)
));
$ses_client = $aws_client->get('Ses');
$ses_result = $ses_client->verifyEmailIdentity(['EmailAddress' => $mailbox_email]);
// Set bounces, complaint, deliveries notification
$ses_client->setIdentityNotificationTopic(array(
'Identity' => $mailbox_email,
'NotificationType' => 'Bounce',
'SnsTopic' => 'arn:aws:sns:eu-west-1:9:ses_bounces'
));
$ses_client->setIdentityNotificationTopic(array(
'Identity' => $mailbox_email,
'NotificationType' => 'Complaint',
'SnsTopic' => 'arn:aws:sns:eu-west-1:9:ses_complaints'
));
$ses_client->setIdentityNotificationTopic(array(
'Identity' => $mailbox_email,
'NotificationType' => 'Delivery',
'SnsTopic' => 'arn:aws:sns:eu-west-1:9:ses_deliveries'
));
$ses_client->SetIdentityFeedbackForwardingEnabled(array(
'Identity' => $mailbox_email,
'ForwardingEnabled' => false
));
In AWS SES for Email Domain Verification you need to do a DNS settings either add a DKIM or TXT record which cannot be done using a API except the domain is in Route 53 and you have access to the account. This are the ways to verify email domain. So email domain verification will have to be done manually.
http://docs.aws.amazon.com/ses/latest/DeveloperGuide/verify-domains.html
You can only verify the Email Address using AWS SES API.
http://docs.aws.amazon.com/ses/latest/DeveloperGuide/verify-email-addresses.html
Verify email
//connect Amazon SES
$ses = new SimpleEmailService($this->AccessKey, $this->SecretKey,'email.eu-west-1.amazonaws.com');
//Get verified mail list
$list = $ses->listVerifiedEmailAddresses();
//verify email
$confirm = $ses->verifyEmailAddress('mail#example.com');
Set topic after verify email
$ses = Aws\Ses\SesClient::factory([
'credentials' => [
'key' => $this->AccessKey,
'secret' => $this->SecretKey,
],
'version' => 'latest',
'region' => 'eu-west-1'
]);
$ses_client = $ses->setIdentityNotificationTopic(array(
'Identity' => $email,
'NotificationType' => 'Bounce',
'SnsTopic' => 'arn:aws:sns'
));
$ses_client = $ses->setIdentityNotificationTopic(array(
'Identity' => $email,
'NotificationType' => 'Complaint',
'SnsTopic' => 'arn:aws:sns'
));
As of now (Oct 17, 19), you can generate the txt record for verifying domain through the API.
$result = $client->verifyDomainIdentity([
'Domain' => '<string>', // REQUIRED
]);
AWS Doc