I am using "aws/aws-sdk-php-laravel": "~3.0"
When i am trying to register the android device its throwing the error.
Below is the snapshot of it.
I tried with 2 different code formats but both gives the same exception.
$device = 'gcm_id_here';
$sns = App::make('aws')->createClient('sns');
$result = $sns->createPlatformEndpoint(['Token' => 'device_unique_id',
'PlatformApplicationArn' => $device]);
// or
$credentials = new Credentials('key', 'secret');
$client = new SnsClient([
'version' => 'latest',
'region' => 'us-west-2',
'credentials' => $credentials
]);
$SNSEndPointData = $client->createPlatformEndpoint([
'PlatformApplicationArn' => $device,
'Token' => 'device_unique_id'
]);
Please help me solve this issue.
Related
I'm trying to connect to another account's bucket through "AssumeRole". Through CLI everything is working (I'm just adding "External ID" through parameter "--external-id"), but through SDK - I cannot to find how to add "External ID" correctly.
Code Example:
$stsClient = new StsClient([
'region' => 'us-west-2',
'version' => 'latest',
'credentials' => $provider
]);
$ARN = "arn:aws:iam::12345678:role/some_test_role";
$sessionName = "some-test-session-name";
$externalId = "TEST-EXTERNAL-ID"; //How to pass it into AssumeRole?
$assumeRoleResult = $stsClient->AssumeRole([
'RoleArn' => $ARN,
'RoleSessionName' => $sessionName
]);
I am using own cloud storage Rados s3 server and trying to create a bucket using 3.52 php AWS sdk. Following is the code I am running in my console:
require 'vendor/autoload.php';
use Aws\S3\S3Client;
use Aws\Credentials\CredentialProvider;
$Connection = new S3Client([
'region' => 'us-west-2',
'version' => 'latest',
'endpoint' => 'http://XXX.XX.XX.XXX',
'credentials' => [
'key' => 'xx',
'secret' => 'XX'
],
]);
//create a bucket
$promise =$Connection->createBucket(array('Bucket' => 'pankaj'));
I am getting below fatal error
Fatal error: Uncaught exception 'Aws\S3\Exception\S3Exception' with message 'Error executing "CreateBucket" on "http://pankaj.XXX.XX.XX.XXX/"; AWS HTTP error: cURL error 6: Could not resolve host: pankaj.XXX.XX.XX.XXX; Name or service not known (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)' in /var/www/html/object/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php on line 191
I think it's not accepting your end point which you define.
please use add this key in your client connection
'use_path_style_endpoint' => true
Example :
$s3Client = new S3Client([
'region' => 'us-west-2',
'version' => '2006-03-01',
'use_path_style_endpoint' => true
]);
Remove the endpoint from the client configuration.
require 'vendor/autoload.php';
use Aws\S3\S3Client;
use Aws\Exception\AwsException;
$BUCKET_NAME='<BUCKET-NAME>';
//Create a S3Client
$s3Client = new S3Client([
'region' => 'us-west-2',
'version' => '2006-03-01'
]);
//Creating S3 Bucket
try {
$result = $s3Client->createBucket([
'Bucket' => $BUCKET_NAME,
]);
}catch (AwsException $e) {
// output error message if fails
echo $e->getMessage();
echo "\n";
}
I'm currently struggling with getting a S3 download link working. I've been using this code as reference but when I try to open the file, I get the error:
The authorization mechanism you have provided is not supported. Please
use AWS4-HMAC-SHA256.
I tried a few other scripts floating around, but all ended with some other error message.
Is there an easy way to migrate the script I'm using to make it work with Signature v4?
UPDATE: as suggested by hjpotter92, I used the AWS-SDK and came up with this working code:
$client = S3Client::factory([
'version' => 'latest',
'region' => 'eu-central-1',
'signature' => 'v4',
'credentials' => [
'key' => '12345',
'secret' => 'ABCDE'
]
]);
$cmd = $client->getCommand('GetObject', [
'Bucket' => '###name###',
'Key' => $fileName
]);
$request = $client->createPresignedRequest($cmd, '+2 minutes');
$presignedUrl = (string) $request->getUri();
return $presignedUrl;
I am getting an error 500 when trying to do a SNS publish using the Amazon AWS SDK for PHP. If I run PHP sendPush.php in terminal it works perfectly fine but if I go to the URL in chrome I get an error 500.
Here is my PHP file:
<?php
require 'vendor/autoload.php';
use Aws\Credentials\CredentialProvider;
use Aws\Sns\SnsClient;
$arn = "<my arn endpoint here>";
$message = 'test1';
$provider = CredentialProvider::env();
$client = SnsClient::factory(array(
'profile' => 'default',
'credentials' => $provider,
'version' => 'latest',
'region' => 'us-east-1'
));
$message_atr = array(
'String' => array(
'DataType' => 'String',
'StringValue' => $message
)
);
$publish_message = array('TargetArn' => $arn,'Message' => $message,'MessageAttributes'=> $message_atr);
$client->publish($publish_message);
?>
I had the .aws folder in the wrong location, it works now.
I'm using latest PHP SDK(V3) for Amazon SNS. I have a problem when I'm trying to create an endpoint for a platform (Registering user devices to a platform). The error says I have an "InvalidArgumentException", but I have double checked with the document and I'm passing correct arguments. Please find below my code.
try {
$credentials = new Credentials($SNS_ACCESS_KEY, $SNS_SECRET_KEY);
$s3Client = new S3Client([
'version' => 'latest',
'region' => 'us-west-2',
'credentials' => $credentials
]);
$SNSEndPointData = $s3Client->createPlatformEndpoint([
'PlatformApplicationArn' => $SNS_APP_ARN,
'Token' => $device_token
]);
}
catch(exception $e) {
print $e->__toString();
}
If anyone can help or point me to right direction it is highly appreciated.
Here is the full answer just in case if anyone interested,
require 'vendor/autoload.php';
use Aws\Credentials\Credentials;
use Aws\Sns\SnsClient;
try {
$credentials = new Credentials($SNS_ACCESS_KEY, $SNS_SECRET_KEY);
$client = new SnsClient([
'version' => 'latest',
'region' => 'us-west-2',
'credentials' => $credentials
]);
$SNSEndPointData = $client->createPlatformEndpoint([
'PlatformApplicationArn' => $SNS_APP_ARN,
'Token' => 'phone token'
]);
print $SNSEndPointData;
}
catch(exception $e) {
$message = $e->getMessage();
print $message;
}