I am trying to write a script to automatically update the nameservers that I registered in Route 53.
This can be done via Amazon Rest API:
http://docs.aws.amazon.com/Route53/latest/APIReference/api-update-domain-name-servers.html
Up to this point, I have been using the Amazon PHP SDK...but this SDK doesn't even have support for this command (or a majority of Route 53 commands).
I've spent hours trying to form a request using php+curl. I have everything I need - an acesskeyID, secret key, etc. No matter what I do I can NOT seem to get the signature to be valid. The docs are a nightmare...everything related to PHP immediately points you to the SDK, which is no help here.
Please show me how to make a REST request with PHP, sign it using my key, and get a response.
Edit: Here is what I tried to follow to sign the request.
Which version of the SDK are you using?
According to api v3 docs you can use this:
$result = $client->updateDomainNameservers([/* ... */]);
$promise = $client->updateDomainNameserversAsync([/* ... */]);
And these are the relevant parameters:
$result = $client->updateDomainNameservers([
'DomainName' => '<string>', // REQUIRED
'FIAuthKey' => '<string>',
'Nameservers' => [ // REQUIRED
[
'GlueIps' => ['<string>', ...],
'Name' => '<string>', // REQUIRED
],
// ...
],
]);
If you are not using the latest version of the sdk you can install it using composer:
php composer.phar require aws/aws-sdk-php
or use any of the installation methods here.
I really think its best for you to stick with the SDK, unless really not possible (which I don't think is the case here, correct me if I'm wrong).
If installed using composer you can update your composer.json file to contain:
{
"require": {
"aws/aws-sdk-php": "3.*"
}
}
and run composer update
If you just want to check which version of the sdk you are working with you can run composer info (inside that directory):
> composer info
aws/aws-sdk-php 3.18.32 AWS SDK for PHP - Use Amazon Web Services in your PHP project
guzzlehttp/guzzle 6.2.1 Guzzle is a PHP HTTP client library
guzzlehttp/promises 1.2.0 Guzzle promises library
guzzlehttp/psr7 1.3.1 PSR-7 message implementation
mtdowling/jmespath.php 2.3.0 Declaratively specify how to extract elements from a JSON document
psr/http-message 1.0 Common interface for HTTP messages
Or check the content of the composer.lock file. You should have there the version of the sdk you are using:
"packages": [
{
"name": "aws/aws-sdk-php",
"version": "3.18.32",
"source": {
"type": "git",
"url": "https://github.com/aws/aws-sdk-php.git",
"reference": "84b9927ee116b30babf90a9fc723764672543e29"
},
Make sure you use the last one.
Thanks to #Dekel, I was able to solve this problem. Here is my final code.
require_once '/vendor/autoload.php';
$access_key="XXXXX";
$secret_key="XXXXXXXXXXXX";
$client = Aws\Route53Domains\Route53DomainsClient::factory(array(
'region'=> "us-east-1",
'version'=>'2014-05-15',
'credentials' => array(
'key' => $access_key,
'secret' => $secret_key,
)));
$result = $client->updateDomainNameservers([
'DomainName' => 'example.com',
"Nameservers"=>array(
array("Name"=>"ns.1.com"),
array("Name"=>"ns.2.com")
)
]);
Related
I'm starting a project with Laravel 6.2, added kreait/laravel-firebase and configured it with the .json configuration file to work with Realtime database and works like a charm.
Later I read that Cloud Firestore is better. So I've installed the library google cloud and use the example provided:
public function test(){
$db = new FirestoreClient();
$docRef = $db->collection('users')->document('aturing');
$docRef->set([
'first' => 'Alan',
'middle' => 'Mathison',
'last' => 'Turing',
'born' => 1912
]);
printf('Added data to the aturing document in the users collection.' . PHP_EOL);
}
That request and every request throws me this exception:
Google\Cloud\Core\Exception\ServiceException
{ "message": "Empty update", "code": 14, "status": "UNAVAILABLE", "details": [] }
I searched the docs, forums, everything and I can't find an answer.
Thanks in advance.
I had the same issue in Laravel, the solution is to pin in composer.json grpc/grpc to version 1.19 and then restart apache.
"require": {
"grpc/grpc": "1.19"
}
More details here: https://github.com/googleapis/google-cloud-php/issues/2539
I got same issue on my local in project laravel with xampp php 7.4 and grpc 1.26 but on my remote server working fine with same version grpc
I'm using PHP to try using the Google Cloud Spanner. I already did the gCloud settings and everything, and that's right. Now I need to make the connection via PHP to do a CRUD with the database that is in Spanner, but the code below always returns the error:
PHP Fatal error: Undefined constant 'Grpc\STATUS_UNKNOWN' in
/xxx/xxxx/www/vendor/google/cloud-spanner/Connection/Grpc.php on line
129
The code I have is:
<?php
require 'vendor/autoload.php';
use Google\Cloud\Spanner\SpannerClient;
/* Error start here */
$spanner = new SpannerClient([
'projectId' => 'my-project-id'
]);
$db = $spanner->connect('instance', 'database');
$userQuery = $db->execute('SELECT * FROM usuario WHERE login = #login', [
'parameters' => [
'login' => 'devteam'
]
]);
$user = $userQuery->rows()->current();
echo 'Hello ' . $user['login'];
The requirements I use in the composer are:
"require": {
"google/cloud": "^0.32.1",
"google/cloud-spanner": "^0.2.2"
}
I noticed that if I enter through the browser, the error presented above continues to appear. If I run the command php teste.php on the terminal, it runs the script correctly, ie, the terminal works and the browser does not.
Google Cloud PHP's spanner client is gRPC only. This means to use it you will need to install the gRPC PHP extension:
pecl install grpc
Once you have done that, add google/proto-client-php and google/gax to your composer.json and run composer update. After this is done, the error will be resolved.
For those wanting more detailed instructions, see this page for installing and enabling gRPC for PHP!
Since you mentioned that it works on CLI but not on browser, I can say that you need to enable the grpc extension on your php web server config.
E.g. Add
extension=grpc.so to your /etc/php/5.6/apache2/php.ini
I am trying to use Guzzle client to post requests to an API, and I am getting an error message saying,
InvalidArgumentException: "No method is configured to handle the form_params config key"
This is what I have tried:
$response = $this->guzzle->post("https://example.com",[
'form_params'=> [
'client_id'=>$this->client_id,
'authorization_code'=>$this->authorization_code,
'decoder_query'=> $this->requestQuery
],
]
);
$this->requestQuery is a JSON request.
$response = $this->guzzle->post("https://example.com", [
'body' => [
'client_id' => $this->client_id,
'authorization_code'=> $this->authorization_code,
'decoder_query' => json_encode($this->requestQuery),
]
]);
with this syntax I am getting it woking..
you are probably using a Guzzle version that's before 6.0. update to the latest version and 'form_params' will work just fine. i had the same issue since i was on 5.x version
composer require 'guzzlehttp/guzzle:6.0.1'
and make sure you update your dependencies:
composer update
you'll then see it'll pull in "guzzlehttp/psr7 (1.0.0)" as well. hope that helps.
For me, this ended up being an problem with the actual Guzzle package not being correct. It loaded a version from cache that wasn't the the PSR7 version.
After clearing composer cache
php composer.phar clear-cache
I simply did a new composer install and installed just fine, while fixing the error.
How do I integrate my Yii 2.0 project with Aws ?
I have installed it using composer
"aws/aws-sdk-php": "2.*",
and included the
require '../vendor/aws/aws-autoloader.php';
But when I try to instantiate my S3 client, it keeps telling me that Aws does not exist.
You can refer the following link on github
https://github.com/JDpawar/yii2-aws-s3-sdk
It has the exact details how to use the S3 SDK along with the Yii 2 App.
AWS SDK for Yii2 - Use Amazon Web Services in your Yii2 project
This extension provides the AWS SDK 3 integration for the Yii2 framework
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist fedemotta/yii2-aws-sdk "*"
or add
"fedemotta/yii2-aws-sdk": "*"
to the require section of your composer.json file.
Note: You can still use AWS version 2 if you specify fedemotta/yii2-aws-sdk "1.*"
Usage
To use this extension, simply add the following code in your application configuration:
<?php
return [
//....
'components' => [
'awssdk' => [
'class' => 'fedemotta\awssdk\AwsSdk',
'credentials' => [ //you can use a different method to grant access
'key' => 'your-aws-key',
'secret' => 'your-aws-secret',
],
'region' => 'your-aws-region', //i.e.: 'us-east-1'
'version' => 'your-aws-version', //i.e.: 'latest'
],
],
];
?>
Getting all balancer names from AWS:
<?php
$aws = Yii::$app->awssdk->getAwsSdk();
$elb = $aws->createElasticloadbalancing();
$load_balancers = $elb->describeLoadBalancers()->toArray();
if (isset($load_balancers['LoadBalancerDescriptions'])){
foreach ($load_balancers['LoadBalancerDescriptions'] as $balancer){
if (isset($balancer['LoadBalancerName'])){
echo $balancer['LoadBalancerName'];
}
}
}
?>
Download an object from S3:
<?php
//specify the region if it is different than the main configuration region
Yii::$app->awssdk->region = 'sa-east-1';
$aws = Yii::$app->awssdk->getAwsSdk();
//use s3
$s3 = $aws->createS3();
$result = $s3->listObjects(['Bucket' => 'your-bucket-id',
"Prefix" => "your-path"])->toArray();
//get the last object from s3
$object = end($result['Contents']);
$key = $object['Key'];
$file = $s3->getObject([
'Bucket' => 'your-bucket-id',
'Key' => $key
]);
//download the file
header('Content-Type: ' . $file['ContentType']);
echo $file['Body'];
?>
Run the Composer command to install s3 extension. composer require frostealth/yii2-aws-s3 ~1.0#stable
Open common/config/main.php file and add below code into "components" section. "s3bucket" => [ "class" => \frostealth\yii2\aws\s3\Storage::className(), "region" => "Your region", "credentials" => [ "key" => "your aws s3 key", "secret" => "your aws s3 secret", ], "bucket" => "your aws s3 bucket", "defaultAcl" => \frostealth\yii2\aws\s3\Storage::ACL_PUBLIC_READ, "debug" => false, // bool|array ],
Use below code to upload image on s3 $s3 = Yii::$app->get('s3bucket')->upload('upload image name', 'path of local folder where image located');
After uploading you get status code and image url. you can get like below $status = $s3["#metadata"]["statusCode"]; $imageUrl = $s3["#metadata"]["effectiveUri"];
I reimport my extension using composer,
and adding
require (\Yii::getAlias('#vendor/autoload.php'));
Somehow I got it working by adding 'autoload' in json composer
"autoload": {
"psr-4": {
"vendor\\aws\\" :""
}
}
and then run
php composer.phar dumpautoload
Was looking around for this for a few hours and only found other packages to solve the issue. Wanted to implement the AWS package directly. So from
Installed the latest aws-sdk via composer.
I am using
"aws/aws-sdk-php": "^3.259"
Make sure aws source and location is correct in the vendor/composer/autoload_psr4.php
'Aws\\' => array($vendorDir . '/aws/aws-sdk-php/src')
After that ran composer update as mentioned by #Karate_Dog
php composer.phar dumpautoload
I need help regarding omnipay pin payments. i have no clue how to integrate this to cake php.
i tried this sample code but dint get success
$gateway = GatewayFactory::create('Pin');
$gateway->setSecretKey('your-secret-api-key');
$gateway->purchase([
'email' => 'customer#email.com',
'description' => 'Widgets',
'amount' => '4999',
'currency' => 'USD',
'card_token' => 'card_nytGw7koRg23EEp9NTmz9w',
'ip_address' => '1.2.3.4'
])->send();
Fatal error: Class 'GatewayFactory'
Please help me . Thanks in advance
You need to use Composer to install Omnipay. This is explained in the Omnipay Readme.
Make a file called composer.json in the root of your project directory:
{
"require": {
"omnipay/pin": "~2.0"
}
}
Then run the following commands in a terminal window:
$ curl -s http://getcomposer.org/installer | php
$ php composer.phar update
This will download the Omnipay files into your vendor/ directory.
Next, you will need to put the following line at the top of your index.php file, to register the composer autoloader:
require 'vendor/autoload.php';
Finally, you can use Omnipay in your project to create the Pin gateway:
$gateway = Omnipay\Omnipay::create('Stripe');