async-aws/sns
AsyncAws SNS client for PHP: publish messages, send SMS, manage topics and subscriptions, and integrate with AWS SNS without the full AWS SDK. Lightweight, async-friendly, PSR-18/PSR-7 compatible for modern apps and Laravel.
SnsClient as a singleton)..env or config/ files for AWS credentials/regions, adhering to Laravel’s 12-factor practices.queue:work or Horizon for async job processing triggered by SNS.Notifications facade for SNS-backed channels (e.g., SMS, email via SNS).PublishInput, SubscribeInput), reducing runtime errors.aws/aws-sdk-php).us-isob-west-1).| Risk | Impact | Mitigation Strategy |
|---|---|---|
| AWS Credential Leaks | High (security breach) | Enforce IAM roles (EC2/ECS) or Laravel’s env() with AWS_ACCESS_KEY_ID. |
| Throttling/Retries | Medium (latency spikes) | Integrate with Laravel’s queue retries or add GuzzleHttp middleware for backoff. |
| Message Schema Drift | High (consumer failures) | Use JSON Schema validation (e.g., spatie/laravel-json-validate) for published messages. |
| Testing Complexity | Medium (mocking AWS) | Use vcrphp for HTTP recordings or localstack for integration tests. |
| Region Misconfiguration | Medium (failed requests) | Validate regions against AsyncAws\Sns\Enum\Region enum or use Laravel’s config/. |
| FIFO Topic Deadlocks | Low (if misconfigured) | Monitor SnsClient logs for SequenceNumber conflicts; use MessageDeduplicationId. |
Sns::publish('topic', ['data' => $user->toArray()]) vs. json_encode($user).SnsClient exceptions to laravel-logger.sns:Publish only for specific topics)?Mockery) or use integration tests with localstack?$this->mock(SnsClient::class)->shouldReceive('publish')->once();
| Laravel Component | Integration Strategy | Example Code |
|---|---|---|
| Service Container | Bind SnsClient as a singleton in AppServiceProvider. |
```php |
$this->app->singleton(SnsClient::class, function ($app) {
return new SnsClient([
'region' => config('services.aws.region'),
'credentials' => config('services.aws.credentials'),
]);
});
``` |
| Configuration | Extend config/services.php for AWS SNS settings. | php 'sns' => [ 'default_topic' => env('AWS_SNS_DEFAULT_TOPIC'), 'regions' => ['us-east-1', 'eu-west-1'], ], |
| Queue System | Use Laravel’s queue workers to process SNS-triggered jobs. | php Sns::subscribe('order-events.topic', new SqsSubscription('orders-queue')); |
| Events | Dispatch Laravel events to SNS via a listener. | php Event::listen(UserRegistered::class, function ($event) { Sns::publish('users.topic', json_encode($event)); }); |
| Notifications | Extend SnsChannel for user alerts (e.g., SMS, email via SNS). | php use Illuminate\Notifications\SnsMessage; Sns::publish('notifications.topic', (new SnsMessage($user))->toArray()); |
| Commands/Jobs | Trigger SNS publishes from Artisan commands or jobs. | php Sns::publish('logs.topic', ['level' => 'error', 'message' => $exception->getMessage()]); |
| Middleware | Add SNS-specific middleware (e.g., auth, validation) before publishing. | php $sns = app(SnsClient::class); $sns->publish('topic', $message)->withMiddleware(new ValidateMessage()); |
async-aws/sns for a single use case (e.g., user notifications).Queue::push() for cross-service events with Sns::publish().PublishBatch for high-volume messages (e.g., logs).| Compatibility Check | Status | Notes |
|---|---|---|
| Laravel 10+ (PHP 8.2+) | ✅ Fully Compatible | Matches async-aws/sns’s PHP 8.2+ requirement. |
| AWS SDK v3 | ✅ Supported | Underlying async-aws/core aligns with AWS API changes. |
| GuzzleHttp 7+ | ✅ Supported | Used by async-aws/core for HTTP requests. |
| Symfony Components | ⚠️ Partial | Avoids `symfony |
How can I help you explore Laravel packages today?