PHP code example of sunaoka / laravel-aws-sdk-php
1. Go to this page and download the library: Download sunaoka/laravel-aws-sdk-php library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sunaoka / laravel-aws-sdk-php example snippets
return [
'credentials' => [
'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,
// ],
];
$s3 = \AWS::createS3();
$result = $s3->getObject([
'Bucket' => 'Bucket',
'Key' => 'Key',
]);
echo $result['Body'];
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
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
bash
php artisan vendor:publish --tag=aws-config