nekman / aws-ring-http-signer
Sign Ring HTTP calls using AWS credentials
Installs: 30 889
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^7.4||^8.0
- aws/aws-sdk-php: ^3.0
- guzzlehttp/psr7: ^1.0
- guzzlehttp/ringphp: ^1.0
- psr/http-message: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.15
- php-coveralls/php-coveralls: ^2.1
- phpunit/phpunit: ^9.0
Suggests
- elasticsearch/elasticsearch: Sign Elasticsearch requests using AWS credentials
README
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.