https://github.com/sunaoka/laravel-aws-sdk-php
AWS Service Provider for Laravel
https://github.com/sunaoka/laravel-aws-sdk-php
aws laravel php sdk
Last synced: 9 months ago
JSON representation
AWS Service Provider for Laravel
- Host: GitHub
- URL: https://github.com/sunaoka/laravel-aws-sdk-php
- Owner: sunaoka
- License: apache-2.0
- Created: 2023-02-21T05:47:10.000Z (over 3 years ago)
- Default Branch: develop
- Last Pushed: 2025-07-17T08:51:50.000Z (12 months ago)
- Last Synced: 2025-10-14T16:04:04.075Z (9 months ago)
- Topics: aws, laravel, php, sdk
- Language: PHP
- Homepage: https://packagist.org/packages/sunaoka/laravel-aws-sdk-php
- Size: 54.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AWS Service Provider for Laravel
[](https://packagist.org/packages/sunaoka/laravel-aws-sdk-php)
[](https://packagist.org/packages/sunaoka/laravel-aws-sdk-php)
[](composer.json)
[](https://laravel.com/)
[](https://github.com/sunaoka/laravel-aws-sdk-php/actions/workflows/test.yml)
[](https://codecov.io/gh/sunaoka/laravel-aws-sdk-php)
----
## Installation
```bash
composer require sunaoka/laravel-aws-sdk-php
```
## Configurations
```bash
php artisan vendor:publish --tag=aws-config
```
The settings can be found in the generated `config/aws.php` configuration file.
```php
[
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'token' => env('AWS_SESSION_TOKEN'),
],
'region' => env('AWS_DEFAULT_REGION'),
'version' => env('AWS_API_VERSION', 'latest'),
'endpoint' => env('AWS_ENDPOINT'),
// Override Configuration for specific services
// 'S3' => [
// 'use_path_style_endpoint' => false,
// ],
];
```
## Usage
```php
$s3 = \AWS::createS3();
$result = $s3->getObject([
'Bucket' => 'Bucket',
'Key' => 'Key',
]);
echo $result['Body'];
```
## Testing
You may use the `AWS` facade's `fake` method to apply the mock handler.
For more information on mock handlers, please refer to the [Developer Guide](https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_handlers-and-middleware.html).
```php
use Aws\Result;
use Aws\MockHandler;
use Aws\CommandInterface;
use Psr\Http\Message\RequestInterface;
use Aws\Exception\AwsException;
$mock = new MockHandler();
$mock->append(new Result(['Body' => 'foo']));
$mock->append(function (CommandInterface $cmd, RequestInterface $req) {
return new AwsException('Mock exception', $cmd);
});
\AWS::fake($mock);
$s3 = \AWS::createS3();
$result = $s3->getObject([
'Bucket' => 'Bucket',
'Key' => 'Key',
]);
echo $result['Body']; // foo
```
Mock handlers can also be set for each client.
```php
use Aws\DynamoDB\DynamoDbClient;
use Aws\MockHandler;
use Aws\Result;
use Aws\S3\S3Client;
$mockHandlers = [
S3Client::class => new MockHandler([
new Result(['Body' => __METHOD__]),
]),
DynamoDbClient::class => new MockHandler([
new Result(['TableNames' => ['Table1', 'Table2', 'Table3']]),
]),
];
\AWS::fake($mockHandlers);
$s3 = \AWS::createS3();
$result = $s3->getObject([
'Bucket' => 'Bucket',
'Key' => 'Key',
]);
echo $result['Body']; // foo
$dynamoDb = \AWS::createDynamoDb();
$result = $dynamoDb->listTables();
echo $result['TableNames'][0]; // Table1
```