- How do I install aws/aws-sdk-php in a Laravel 10+ project?
- Run `composer require aws/aws-sdk-php` in your project root. For Laravel-specific integrations, also install `composer require aws/aws-sdk-php-laravel` to leverage pre-configured service providers for S3, SQS, DynamoDB, and more. Ensure your `php.ini` includes cURL and OpenSSL extensions for full functionality.
- Which Laravel versions officially support aws/aws-sdk-php v3?
- The SDK requires PHP 8.1+, so it works with Laravel 10+ (released in 2023). For Laravel 9 or older, use v2 of the SDK, but note it lacks PHP 8.1+ features like named arguments. Always check Laravel’s [upgrade guide](https://laravel.com/docs/upgrade) for compatibility.
- Can I use this SDK for serverless Laravel apps (e.g., Lambda)?
- Yes, but optimize for cold starts by provisioning Lambda concurrency or using AWS Powertools for PHP. The SDK supports async operations via Guzzle, which integrates with Laravel Queues. For DynamoDB, pair it with `spatie/laravel-dynamodb` for Eloquent-like queries.
- How do I configure credentials securely in Laravel?
- Avoid hardcoding keys. Use IAM roles (for EC2/Lambda), Laravel’s `.env` with encrypted values, or AWS Secrets Manager. The `aws/aws-sdk-php-laravel` package auto-resolves credentials from `.env` or IAM roles, reducing manual setup.
- Is there a way to reduce the SDK’s ~50MB footprint if I only need S3?
- Yes, install only the S3 client with `composer require aws/aws-sdk-s3`. This avoids loading unused services. For Laravel, combine this with `aws/aws-sdk-php-laravel` for S3-specific providers. Check the [SDK’s modular installation guide](https://docs.aws.amazon.com/aws-sdk-php/v3/developer-guide/guide_installation.html) for other service-specific packages.
- How do I handle errors or retries for AWS API calls in Laravel?
- Use Guzzle’s middleware for retries or Laravel’s `Http` client wrapper. Example: `$client->withConfig(['http_client' => LaravelHttpClient::create()])`. For DynamoDB, `spatie/laravel-dynamodb` provides Eloquent exceptions. Log errors via Laravel’s `Log` facade or AWS CloudWatch.
- Can I use this SDK with Laravel’s Storage facade for S3?
- Yes, the SDK powers Laravel’s S3 filesystem driver. Configure it in `config/filesystems.php` with `disk: ['s3' => ...]`. Use `Storage::disk('s3')->put()` for seamless local/S3 file handling. The SDK’s S3 stream wrapper (`s3://`) enables direct filesystem operations.
- What are the alternatives to aws/aws-sdk-php for Laravel?
- For lightweight needs, consider `league/flysystem-aws-s3` (S3-only) or `spatie/laravel-dynamodb` (DynamoDB ORM). For full AWS support, `aws/aws-sdk-php` is the official choice, but `guzzlehttp/guzzle` alone can work for basic HTTP requests. Evaluate trade-offs like maintenance and feature parity.
- How do I test Laravel apps using aws/aws-sdk-php in CI/CD?
- Mock AWS services with libraries like `mockery` or `php-mock-aws`. For S3, use `league/flysystem` with in-memory adapters. For DynamoDB, `spatie/laravel-dynamodb` supports local testing with `dynamodb-local`. Configure `.env.testing` with dummy credentials and use Laravel’s `Mocker` trait for HTTP clients.
- Does aws/aws-sdk-php support async operations like SQS queue processing?
- Yes, the SDK’s Guzzle integration enables async requests. For SQS, use Laravel Queues with the `sqs` connector: `Queue::connect('sqs')->push()`. Process messages with `sqs:consume` or Laravel’s `ShouldQueue` jobs. Monitor async jobs via Laravel Horizon or AWS CloudWatch.