Amazon SNS not working - php

I have imported 'aws-autoloader.php' and used AWS-SDK php library
$sns = SnsClient::factory(array('key' => "******",
'secret' => "*******",
'region' => "us-east-1"));
But I cant able to get any responds. I already used this key and secret in AWS S3 but here its not working help me regarding this.

Related

Elastic Beanstalk not connecting to Amazon DynamoDB

This is a very strange problem. I have just setup my application on Elastic Beanstalk, the connection which I made with Amazon DynamoDB is working fine but when i made a connection through an AJAX call , it is not connecting and also it is not showing any error. Please help me guys
I have tried changing my role from aws-elasticbeanstalk-service-role to aws-elasticbeanstalk-ec2-role. But still no luck!
I am using the below code to make the connection -
$credentials = new \Aws\Credentials\Credentials(AWS_KEY, AWS_SECRET);
$client = new \Aws\DynamoDb\DynamoDbClient([
'region' => 'us-west-2',
'version' => 'latest',
'credentials' => $credentials
]);

AWS SNS not working on live ec2 server using PHP AWS SDK

I have used SNS service to send SMS on mobile. I have used PHP AWS SDK to server this purpose.
I have tested script in our local server and it sends sms on mobile successfully but when i upload the script in ec2 server then it does not work.
Script hang the web page and sending sms does not work. It does not give any error and loads the page until it get timeout.
We have used http://xxxx.us-west-1.compute.amazonaws.com/ AWS ec2 instance.
My php script is as follows:
require 'vendor/aws-sdk/aws-autoloader.php';
use Aws\S3\SnsClient;
$params = array(
'credentials' => array(
'key' => AWS_ACCESS_KEY,
'secret' => AWS_SECRET_KEY,
),
'region' => 'us-east-1',
'version' => 'latest'
);
$sns = new \Aws\Sns\SnsClient($params);
$result = $sns->publish([
'Message' => "Message here", // REQUIRED
"SMSType" => "Transactional",
'PhoneNumber' => "xxxx", // phone number with country code
'MessageStructure' => 'SMS'
]);
Please suggest.
what we are doing wrong?
Is it any server configuration required to send SMS? or
Do we need to create another ec2 instance with different AWS Region?

AWS S3Client PHP suddenly doesn't work anymore

today my web site which usually auto logs to aws s3 by php, can't connect anymore; the code hasn't changed at all.
$s3Client = new S3Client([
'region' => 'eu-west-1',
'version' => 'latest',
'credentials' => [
'key' => $key,
'secret' => $secret,
],
'http' => [
'verify' => '../ssl_crt/cacert.pem'
]
]);
//echo var_dump($s3Client);
//Listing all S3 Bucket
$result = $s3Client->listBuckets();
the code above which has worked fine till yesterday now gets tomeout connection and therefore fails listing buckets.
I have read amazon has changed something in the permissions/policy, but I can't find how this can be related to PHP s3Client... maybe I could just change some setting in AWS S3 control panel, but I can't figure out what...Has anyone experienced the same issue

setting up cloudfront with php sdk

I am trying to configure the the amazon cloud front, I have successfully created clouldflayer url and access private s3 bucket from it via console. Now I am trying to do it by php-sdk for that I have tried following code
use Aws\CloudFront\CloudFrontClient;
$cle = new CloudFrontClient([
'version' => 'latest',
'region' => 'us-west-2',
'credentials.ini' => [
'key' => 'credentials\pk-myKey.pem',
'secret' => 'secret',
],
]);
$result = $cle->getCloudFrontOriginAccessIdentity([
'Id' => '****', // REQUIRED
]);
print_r($result);
but I am getting error
Fatal error: Uncaught exception 'Aws\CloudFront\Exception\CloudFrontException' with message 'Error executing "GetCloudFrontOriginAccessIdentity" on "https://cloudfront.amazonaws.com/2015-04-17/origin-access-identity/cloudfront/SDF345G";
AWS HTTP error: Client error: 403 SignatureDoesNotMatch (client): Credential should be scoped to a valid region, not 'us-west-2'. -
and I have tried all reason one by one but its not working
Credential should be scoped to a valid region, not 'us-west-2'.
Unlike most of AWS, CloudFront is not a regional service, it's a global one, configured and managed through us-east-1, regardless of the region where any of the related services (S3, EC2, etc.) are deployed.
'region' => 'us-east-1',

How to start an AWS Ec2 instance via https using PHP?

I'm using the AWS SDK for PHP version 2 to start and stop an Ec2 instance.
How can i set the Ec2Client object (or what method should i choose) to use an https connection instead of http?
Can someone help me?
Thanks.
Is it not already using an https connection by default?
You can set the EC2 client to use either http or https using the "scheme" option when instantiating the client.
$client = Aws\Ec2\Ec2Client::factory(array(
'key' => '<aws access key>',
'secret' => '<aws secret key>',
'region' => '<region name>',
'scheme' => 'https',
));

Categories