Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

S3 Laravel Package

async-aws/s3

AsyncAws S3 is a lightweight, async-friendly AWS S3 API client for PHP. Install via Composer and use it to upload, download, list, and manage buckets and objects with a modern, typed client. Part of the AsyncAws suite.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Pros:

    • Async-first design: Aligns with Laravel’s growing adoption of async/await (PHP 8.1+) and Symfony’s async components, enabling non-blocking S3 operations (e.g., uploads/downloads) without manual queueing.
    • AWS API parity: Supports 90%+ of S3 features (e.g., lifecycle policies, versioning, checksums, access points, FSx integration), reducing custom wrapper logic for advanced use cases.
    • Type safety: Strong PHP 8.2+ typing (e.g., int for ContentLength instead of string) improves IDE support and reduces runtime errors.
    • Region agnosticism: Dynamically handles AWS’s expanding regions (e.g., us-isob-west-1, eusc-de-east-1) via configurable endpoints, critical for global Laravel deployments.
    • Checksum validation: Supports 5 algorithms (MD5, SHA-512, XXHash, CRC64NVME) for data integrity, addressing compliance/validation needs.
  • Cons:

    • No built-in Laravel integration: Requires manual DI (e.g., via Laravel’s bind() or service container) or a facade wrapper.
    • Async complexity: Non-blocking operations may require custom middleware (e.g., AsyncAws\S3\Middleware\RetryMiddleware) or queue workers for Laravel’s synchronous HTTP layer.
    • Deprecation risks: PHP 8.2+ only (drops PHP 7.x support), which may conflict with legacy Laravel 8.x apps.

Integration Feasibility

  • Laravel Ecosystem Fit:
    • Filesystem compatibility: Can replace Laravel’s Filesystem contracts (e.g., Illuminate\Contracts\Filesystem\Filesystem) for S3 via a custom adapter (e.g., AsyncAwsS3Adapter).
    • Queue integration: Async operations can be offloaded to Laravel Queues (e.g., S3UploadJob) for background processing.
    • Vapor/Serverless: Ideal for AWS Lambda/Vapor deployments due to native async support and low overhead.
  • Existing Stack Conflicts:
    • AWSSDK vs. AsyncAws: If the app already uses aws/aws-sdk-php, this introduces dual SDK maintenance (though AsyncAws is lighter).
    • Laravel Cache/S3: May conflict with fruitcake/laravel-caching or spatie/laravel-medialibrary if they use the AWSSDK.

Technical Risk

  • High:
    • Async pitfalls: Race conditions if async operations aren’t properly awaited or queued (e.g., concurrent uploads corrupting objects).
    • Error handling: AsyncAws throws exceptions asynchronously; Laravel’s sync error handlers (e.g., try/catch) won’t catch them without middleware.
    • Region/endpoint mismatches: Misconfigured regions (e.g., us-east-1 vs. us-east-1-fips) can cause silent failures.
  • Mitigation:
    • Testing: Use AsyncAws\S3\Middleware\RetryMiddleware with exponential backoff.
    • Monitoring: Integrate with Laravel Horizon or Sentry to track async failures.
    • Fallback: Provide a sync wrapper (e.g., S3Client::promise()->getObject()) for critical paths.

Key Questions

  1. Async Strategy:
    • Will async operations be handled via Laravel Queues, or will the app use raw Promises?
    • How will progress tracking (e.g., uploads) be implemented (e.g., AsyncAws\S3\Result\UploadPartOutput + custom events)?
  2. Error Recovery:
    • How will failed async operations (e.g., timeouts) be retried or logged?
    • Will dead-letter queues (DLQ) be used for failed jobs?
  3. Performance:
    • Will chunked uploads (sendChunkedBody) be enabled for large files (>100MB)?
    • How will concurrency be managed (e.g., AsyncAws\S3\Middleware\ThrottleMiddleware)?
  4. Cost:
    • Will S3 Express One Zone or FSx storage classes be used, requiring region-specific optimizations?
  5. Compliance:
    • Are checksums (e.g., SHA-512) required for audit trails? If so, how will they be validated post-upload?

Integration Approach

Stack Fit

  • Laravel Core:
    • Service Container: Register AsyncAws\S3\S3Client as a singleton with AWS credentials bound to config('services.aws').
      $app->bind('async-aws.s3', fn() => new S3Client([
          'credentials' => $app['config']['services.aws'],
          'region' => $app['config']['services.aws.region'],
          'endpoint' => env('AWS_ENDPOINT'), // For VPC/S3 Express
      ]));
      
    • Filesystem Adapter: Extend Illuminate\Filesystem\Filesystem to delegate to S3Client:
      class AsyncAwsS3Adapter extends Filesystem {
          public function __construct(S3Client $client) {
              $this->client = $client;
          }
          public function put($path, $contents, array $options = []) {
              $this->client->putObject([
                  'Bucket' => $this->client->getBucket(),
                  'Key' => $path,
                  'Body' => $contents,
                  'ContentType' => $options['content_type'] ?? 'application/octet-stream',
              ]);
          }
      }
      
  • Async Handling:
    • Queues: Dispatch async jobs (e.g., S3UploadJob) with dispatchSync() for immediate execution or dispatch() for background processing.
    • Promises: Use await for critical paths (PHP 8.1+):
      $result = await $s3Client->getObject(['Bucket' => 'bucket', 'Key' => 'file.txt']);
      
  • Middleware:
    • Add AsyncAws\S3\Middleware\RetryMiddleware globally for retries:
      $s3Client->registerMiddleware(new RetryMiddleware());
      

Migration Path

  1. Phase 1: Pilot Feature
    • Replace a single S3-dependent feature (e.g., avatar uploads) with async-aws/s3.
    • Use a sync wrapper (e.g., S3Client::promise()->getObject()) to avoid async complexity.
  2. Phase 2: Async Adoption
    • Migrate to async operations for non-critical paths (e.g., logs, backups).
    • Implement a queue listener to handle async failures.
  3. Phase 3: Full Replacement
    • Replace all AWSSDK calls with async-aws/s3.
    • Deprecate legacy SDK code via Laravel’s deprecated() helper.

Compatibility

  • Laravel Versions:
    • Supported: Laravel 10+ (PHP 8.2+). For Laravel 9.x, use async-aws/s3:2.x (PHP 8.1) with a polyfill.
    • Unsupported: Laravel <9.x (PHP <8.1) due to async/await limitations.
  • AWS SDK Conflicts:
    • If using aws/aws-sdk-php, remove it or use a composer alias to avoid version conflicts.
  • Third-Party Packages:
    • spatie/laravel-medialibrary: Replace S3Adapter with AsyncAwsS3Adapter.
    • fruitcake/laravel-caching: Extend S3CacheStore to use async-aws/s3.

Sequencing

  1. Infrastructure:
    • Update php.ini to enable opcache.jit_buffer_size (for PHP 8.2+ async optimizations).
    • Configure AWS credentials in .env:
      AWS_ACCESS_KEY_ID=...
      AWS_SECRET_ACCESS_KEY=...
      AWS_DEFAULT_REGION=us-east-1
      
  2. Code:
    • Install the package: composer require async-aws/s3.
    • Register the client in AppServiceProvider.
  3. Testing:
    • Mock S3Client in unit tests using AsyncAws\S3\Mock\S3Client.
    • Test async operations with await in PHPUnit.
  4. Deployment:
    • Gradually roll out async features behind feature flags.
    • Monitor S3 latency and error rates in CloudWatch.

Operational Impact

Maintenance

  • Pros:
    • Reduced boilerplate: AsyncAws handles AWS API quirks (e.g., pagination, retries) out-of-the-box.
    • Centralized config: AWS settings (regions, endpoints) are managed in config/services.php.
    • Automated updates: AsyncAws follows AWS API changes closely (e.g., new regions, checksums).
  • Cons:
    • Dependency updates: Requires monitoring async-aws/s3 for breaking
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope