nekman/aws-ring-http-signer

This package is abandoned and no longer maintained. No replacement package was suggested.

Sign Ring HTTP calls using AWS credentials

2.0.0 2021-01-10 14:36 UTC

This package is auto-updated.

Last update: 2022-01-15 08:57:40 UTC


README

Build Status Coverage Status

RingPHP has been discontinued. This package does not make sense any more.

In order for AWS to know who/what is making the request it needs to be signed. Using this package, you can sign RingPHP requests with AWS credentials.

Do you want to use this with your Elasticsearch instance hosted on AWS? See the Usage with Elasticsearch section below.

Usage

Install with Composer:

composer require nekman/aws-ring-http-signer

In order to instantiate a new instance of the library, use the factory. Then wrap your Ring HTTP handler with the middleware and use it as normal:

use GuzzleHttp\Ring\Client\CurlHandler;
use Aws\Signature\SignatureV4;
use Nekman\AwsRingHttpSigner\AwsRingHttpSignerFactory;

$signature = new SignatureV4($awsService, $awsRegion); // How do I create this? Please consult the AWS documentation for the service you are using.
$awsRingHttpSigner = AwsRingHttpSignerFactory::create($signature);

$defaultHandler = new CurlHandler(); // Or use whatever handler you already have available.
$handler = $awsRingHttpSigner($defaultHandler);

// And you're done! Use the $handler as you normally would

Usage with Elasticsearch

Install with Composer:

composer require nekman/aws-ring-http-signer elasticsearch/elasticsearch

In order to instantiate a new instance of the library, use the factory. Then wrap your the Elasticsearch client with the middleware and use it as normal:

use Elasticsearch\ClientBuilder;
use Nekman\AwsRingHttpSigner\AwsRingHttpSignerFactory;

$awsRingHttpSigner = AwsRingHttpSignerFactory::create($awsRegion);
$handler = $awsRingHttpSigner(ClientBuilder::defaultHandler()); 

$client = ClientBuilder::create()
    ->setHandler($handler)
    ->build();

// And you're done! Use the $client as you normally would

AWS Credentials Provider and signatures

By default the library will use the default credentials provider provided by AWS. There are many other ways to load credentials which you can read about in the AWS documentation. Consult the AWS documentation on how to create a SignatureInterface.

Example

Lets say you want to provide static credentials from environment variables:

use Nekman\AwsRingHttpSigner\AwsRingHttpSignerFactory;
use Aws\Credentials\CredentialProvider;
use Aws\Credentials\Credentials;

$credentials = new Credentials(getenv("AWS_KEY"), getenv("AWS_SECRET"));
$credentialProvider = CredentialProvider::fromCredentials($credentials);

$awsRingHttpSigner = AwsRingHttpSignerFactory::create($awsRegion, $credentialProvider);

Consult the AWS documentation for more information.

Versioning

This project complies with Semantic Versioning.

Changelog

For a complete list of changes, and how to migrate between major versions, see releases page.