hellohellosharp hellohellosharp - 4 months ago 23
PHP Question

Amazon PHP Rest API with CURL

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.

Answer

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.

Comments