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

Async Aws Bundle Laravel Package

async-aws/async-aws-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install the Bundle:

    composer require async-aws/async-aws-bundle
    
  2. Enable the Bundle: Add to config/bundles.php (Symfony):

    return [
        // ...
        AsyncAws\Bundle\AsyncAwsBundle::class => ['all' => true],
    ];
    

    For Laravel, manually register a ServiceProvider (see Implementation Patterns).

  3. Configure AWS Clients: Create config/packages/async_aws.yaml (Symfony) or config/async_aws.php (Laravel):

    # Symfony example
    async_aws:
        clients:
            s3:
                region: 'us-east-1'
                version: 'latest'
                credentials:
                    provider: 'static'
                    key: '%env(AWS_ACCESS_KEY_ID)%'
                    secret: '%env(AWS_SECRET_ACCESS_KEY)%'
    
  4. Autowire a Client:

    // Symfony
    use AsyncAws\S3\S3ClientInterface;
    
    class MyService {
        public function __construct(private S3ClientInterface $s3) {}
    }
    

    For Laravel, use a ClientFactory or bind the interface manually.

  5. First Use Case: Upload a file asynchronously:

    $result = $this->s3->putObject([
        'Bucket' => 'my-bucket',
        'Key'    => 'file.txt',
        'Body'   => fopen('local-file.txt', 'r'),
    ]);
    

Implementation Patterns

Symfony-Specific Workflows

  1. Environment-Specific Configs: Override defaults per environment (e.g., config/packages/dev/async_aws.yaml):

    async_aws:
        clients:
            s3:
                region: 'eu-west-1'  # Override for dev
    
  2. Credential Providers: Use SSM or Secrets Manager for dynamic credentials:

    async_aws:
        credential:
            provider: 'ssm'
            parameters:
                - '/prod/aws/access_key'
                - '/prod/aws/secret_key'
    
  3. Client Overrides: Extend or replace a client in a service:

    // config/services.yaml
    services:
        App\Service\CustomS3Client:
            parent: asyncAws.s3Client
            arguments:
                - '@custom_s3_config'  # Custom config service
    
  4. Event-Driven Patterns: Combine with Symfony Messenger for async processing:

    use AsyncAws\Sqs\SqsClientInterface;
    use Symfony\Component\Messenger\MessageBusInterface;
    
    class SqsConsumer {
        public function __construct(
            private SqsClientInterface $sqs,
            private MessageBusInterface $bus
        ) {}
    
        public function consume(): void {
            $messages = $this->sqs->receiveMessage(['QueueUrl' => 'my-queue']);
            foreach ($messages as $message) {
                $this->bus->dispatch(new ProcessMessage($message));
            }
        }
    }
    

Laravel Adaptation

  1. Service Provider: Create AsyncAwsServiceProvider.php:

    use AsyncAws\Bundle\DependencyInjection\AsyncAwsExtension;
    use Symfony\Component\DependencyInjection\ContainerBuilder;
    
    class AsyncAwsServiceProvider extends \Illuminate\Support\ServiceProvider {
        public function register() {
            $container = $this->app->make(ContainerBuilder::class);
            $extension = new AsyncAwsExtension();
            $extension->load([], $container);
            $this->app->set('asyncAws', $container->get('asyncAws'));
        }
    }
    
  2. Configuration Binding: Bind the config in config/async_aws.php:

    return [
        'clients' => [
            's3' => [
                'region' => env('AWS_REGION', 'us-east-1'),
                'credentials' => [
                    'provider' => 'static',
                    'key' => env('AWS_ACCESS_KEY_ID'),
                    'secret' => env('AWS_SECRET_ACCESS_KEY'),
                ],
            ],
        ],
    ];
    
  3. Autowiring: Extend Laravel’s autowiring in app/Providers/AppServiceProvider.php:

    use Illuminate\Contracts\Container\BindingResolutionException;
    
    public function register(): void {
        app()->resolving(AsyncAws\S3\S3ClientInterface::class, function ($client) {
            return app('asyncAws')->get('s3Client');
        });
    }
    
  4. Async Handling: Use Spatie\Async or Laravel Queues to bridge async/await:

    use Spatie\Async\Async;
    
    Async::onQueue('aws')->run(function () {
        $result = $this->s3->putObject([...]);
        return $result;
    });
    

Integration Tips

  1. Logging: Enable the async_aws Monolog channel in config/packages/monolog.yaml:

    monolog:
        channels: ['async_aws']
    
  2. Retry Strategies: Configure retries per client:

    async_aws:
        clients:
            sqs:
                retry:
                    max_attempts: 3
                    delay: 100  # ms
    
  3. Testing: Use MockClient for unit tests:

    use AsyncAws\S3\MockS3Client;
    
    $mock = new MockS3Client();
    $mock->shouldReceive('putObject')->andReturn(new PutObjectResponse());
    $this->container->set('asyncAws.s3Client', $mock);
    
  4. Performance:

    • Credential Caching: Enable async_aws.credential.cache to avoid repeated IAM calls.
    • Connection Pooling: Reuse clients (e.g., S3ClientInterface) across requests.

Gotchas and Tips

Pitfalls

  1. PHP Version Mismatch:

    • Error: Class 'AsyncAws\...' not found or PHP 8.2 required.
    • Fix: Ensure php >=8.2 and async-aws/core: ^3.0 in composer.json.
  2. Symfony vs. Laravel DI Conflicts:

    • Error: Extension class "AsyncAws\Bundle\DependencyInjection\AsyncAwsExtension" not found in Laravel.
    • Fix: Manually register the AsyncAwsExtension in a ServiceProvider (see Implementation Patterns).
  3. Async/Await Misuse:

    • Error: Call to undefined function await() or hung requests.
    • Fix: Use Spatie\Async or Laravel Queues to handle async operations in a synchronous framework.
  4. Credential Provider Conflicts:

    • Error: Invalid credential provider configuration.
    • Fix: Ensure credential_provider and credential_provider_cache are not both defined (see Changelog 1.12.3).
  5. Missing Services:

    • Error: Service "asyncAws.<client>Client" not found.
    • Fix: Verify the client is listed in async_aws.clients and the async-aws/<service> package is installed (e.g., async-aws/s3).

Debugging Tips

  1. Enable Debug Mode: Set debug: true in config/packages/async_aws.yaml to log client configurations:

    async_aws:
        debug: true
    
  2. Check Logs: Monitor the async_aws channel for credential cache failures or client errors:

    bin/console debug:config async_aws
    
  3. Validate Config: Use Symfony’s config validator:

    bin/console debug:config-validator async_aws
    
  4. Async Debugging: For Laravel, use Spatie\Async\Debugging to inspect async jobs:

    Async::debug();
    

Extension Points

  1. Custom Clients: Extend the bundle by creating a custom Extension:

    use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
    use Symfony\Component\DependencyInjection\ContainerBuilder;
    use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
    use Symfony\Component\Config\FileLocator;
    
    class CustomAsyncAwsExtension extends AsyncAwsExtension {
        public function load(array $configs, ContainerBuilder $container) {
            parent::load($configs, $container);
            $loader = new YamlFileLoader(
                $container,
                new FileLocator(__DIR__.'/../Resources/config')
            );
            $loader->load('custom_clients.yaml');
        }
    }
    
  2. Middleware: Add custom middleware to AWS clients:

    async_aws:
        clients:
            s3:
                middleware:
                    - '@custom_middleware'
    
  3. Event Listeners:

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.
yandex/translate-api
voku/simple_html_dom
league/flysystem-vfs
bkwld/upchuck
filament/spatie-laravel-tags-plugin
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php