aws/aws-sdk-php
AWS SDK for PHP v3 provides a complete client library for Amazon Web Services (S3, DynamoDB, Glacier, and more). Install via Composer, authenticate with AWS credentials, and use service clients to build robust PHP apps with AWS APIs.
Pros:
metadata_directive in MultipartCopy (default: 'COPY') directly benefits Laravel applications using S3 for file storage (e.g., spatie/laravel-medialibrary, intervention/image). Previously, metadata (e.g., Cache-Control, Content-Type) was lost during multipart uploads/copies. This aligns with Laravel’s asset optimization needs (e.g., CDN caching, MIME type preservation).'COPY', ensuring no breaking changes for existing Laravel apps. Explicit 'REPLACE' is required to override, reducing risk of unintended metadata loss.ClientToken for idempotency in Aws\Invoicing APIs (e.g., CreateInvoiceUnit). Useful for Laravel-based billing systems (e.g., SaaS platforms using laravel-cashier + AWS Marketplace). Mitigates duplicate charge risks.spatie/laravel-permission + AWS findings).ListPerformanceAnalysisReportRecommendations enables Laravel to integrate AWS Performance Insights for database optimization (e.g., laravel-debugbar + RDS/Aurora tuning).Cons:
Aws\Bedrock, Aws\GeoPlaces) are irrelevant to Laravel. Only S3 metadata, idempotency, and security scripts have direct impact.SQS, DynamoDB, RDS). The metadata_directive is the sole actionable feature for most teams.Aws\ClientFactory). Test with:
php artisan aws:test-endpoints # Hypothetical; validate custom clients
S3 Metadata Directive:
metadata_directive. Example for spatie/laravel-medialibrary:
use Aws\S3\S3Client;
$s3 = new S3Client([]);
$result = $s3->copyObject([
'bucket' => 'laravel-assets',
'key' => 'optimized-image.jpg',
'copySource' => 'original-image.jpg',
'metadata_directive' => 'COPY', // Preserves Cache-Control, Content-Type, etc.
]);
Storage::disk('s3')->put('file.jpg', file_get_contents('local.jpg'), [
'metadata' => ['Cache-Control' => 'public, max-age=31536000'],
'options' => ['metadata_directive' => 'COPY'], // Ensures metadata is copied
]);
Idempotency (Invoicing):
ClientToken to invoice-related API calls:
use Aws\Invoicing\InvoicingClient;
$invoicing = new InvoicingClient([]);
$response = $invoicing->createInvoiceUnit([
'clientToken' => Str::uuid()->toString(), // Idempotency key
'invoiceUnit' => [...],
]);
Security Scripts:
artisan commands:
public function verifySecurityFinding($findingId) {
$script = Storage::disk('s3')->get("aws-security-scripts/{$findingId}.sh");
exec($script, $output);
return $output;
}
Performance Insights (PI):
laravel-debugbar:
use Aws\PerformanceInsights\PerformanceInsightsClient;
$pi = new PerformanceInsightsClient([]);
$recommendations = $pi->listPerformanceAnalysisReportRecommendations([
'resourceArn' => 'arn:aws:rds:us-east-1:123:db:laravel-db',
]);
Debugbar::info($recommendations);
Testing:
public function test_s3_metadata_preservation() {
$s3 = new S3Client([]);
$s3->putObject([
'bucket' => 'test-bucket',
'key' => 'test.jpg',
'metadata' => ['Cache-Control' => 'public'],
]);
$copyResult = $s3->copyObject([
'bucket' => 'test-bucket',
'key' => 'copied.jpg',
'copySource' => 'test.jpg',
'metadata_directive' => 'COPY',
]);
$this->assertEquals('public', $s3->headObject(['bucket' => 'test-bucket', 'key' => 'copied.jpg'])['Metadata']['cache-control']);
}
public function test_invoicing_idempotency() {
$invoicing = new InvoicingClient([]);
$response1 = $invoicing->createInvoiceUnit([...]);
$response2 = $invoicing->createInvoiceUnit([...]); // Same ClientToken
$this->assertEquals($response1['invoiceUnitId'], $response2['invoiceUnitId']);
}
Breaking Changes:
Aws\ClientFactory). Test with:
php artisan aws:validate-endpoints # Hypothetical; check for BDD-related errors
'COPY', but apps explicitly setting metadata_directive to 'REPLACE' may see unexpected metadata loss if not updated.Performance:
metadata_directive adds minimal overhead (~5–10ms per copy operation). Benchmark Laravel’s asset pipelines:
ab -n 1000 -c 100 POST /api/upload -T multipart/form-data
ClientToken generation.AWS Service Limits:
s3:PutObjectTagging (required for metadata operations).queue:work concurrency limits:
'queue' => [
'concurrency' => env('QUEUE_CONCURRENCY', 5),
],
Cost:
use Aws\S3\S3Client;
$s3 = new S3Client(['region' => 'us-east-1']);
$cost = $s3->getCostExplorer([
'TimePeriod' => ['Start' => now()->subMonth(), 'End' => now()],
'Granularity' => 'DAILY',
'Metrics' => ['BlendedCost'],
]);
queue:failed monitoring to track failures.Security:
{
"Effect": "Allow",
"Action":
How can I help you explore Laravel packages today?