PHPackages                             nightwriter/laravel-events-to-sns - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. nightwriter/laravel-events-to-sns

ActiveLibrary[HTTP &amp; Networking](/categories/http)

nightwriter/laravel-events-to-sns
=================================

Laravel package to push events to AWS SNS

1.0.2(5y ago)05.9k↓26.7%MITPHPPHP &gt;=7.2

Since Nov 23Pushed 2y agoCompare

[ Source](https://github.com/NightWriter/laravel-events-to-sns)[ Packagist](https://packagist.org/packages/nightwriter/laravel-events-to-sns)[ Docs](https://github.com/ralbear/laravel-events-to-sns)[ RSS](/packages/nightwriter-laravel-events-to-sns/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (4)Used By (0)

[![](https://raw.githubusercontent.com/ralbear/laravel-events-to-sns/docs/media/laravel_sns_sqs_laravel.png)](https://laravel.com)

[![Total Downloads](https://camo.githubusercontent.com/b37af3106e30371eb052042795e3f87f9e42f313f4dc8ce7193314ad814d1761/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72616c626561722f6c61726176656c2d6576656e74732d746f2d736e73)](https://packagist.org/packages/ralbear/laravel-events-to-sns)[![Latest Stable Version](https://camo.githubusercontent.com/d01fe808f8fda11b0483bd6a9dbbebbdffc7672c7a6b239efd49046bba02fb95/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72616c626561722f6c61726176656c2d6576656e74732d746f2d736e73)](https://packagist.org/packages/ralbear/laravel-events-to-sns)[![License](https://camo.githubusercontent.com/6579f08dd48728f68b76bd6b1c7edd2a4b9f42d95b0aca00a5d2c11664a32447/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f72616c626561722f6c61726176656c2d6576656e74732d746f2d736e73)](https://packagist.org/packages/ralbear/laravel-events-to-sns)

Laravel events to SNS
---------------------

[](#laravel-events-to-sns)

This library allow us to send Laravel events to an SNS topic, and receive them through a SQS queue.

Install
-------

[](#install)

```
$ composer require nightwriter/laravel-events-to-sns
```

Add the provider to `config/app.php`

```
'providers' => [
    Ralbear\EventsToSns\EventsToSnsProvider::class
 ]

```

Configuration
-------------

[](#configuration)

First step is create this new connection configuration in `config/queue.php`

```
'connections' => [
    'sqs-sns' => [
        'driver' => 'sqs-sns',
        'key' => env('SQS_SNS_ACCESS_KEY_ID') ?? env('AWS_ACCESS_KEY_ID') ?? '',
        'secret' => env('SQS_SNS_SECRET_ACCESS_KEY') ?? env('AWS_SECRET_ACCESS_KEY') ?? '',
        'region' => env('SQS_SNS_DEFAULT_REGION') ?? env('AWS_DEFAULT_REGION') ?? '',
        'base_ARN' => env('SQS_SNS_BASE_ARN') ?? '',
        'valid_topics' => explode(',',env('SQS_SNS_VALID_TOPICS')) ?? [],
        'prefix' => env('SQS_SNS_PREFIX') ?? env('SQS_PREFIX') ?? '',
        'queue' => env('SQS_SNS_QUEUE') ?? env('SQS_QUEUE') ?? '',
        'env_postfix' => env('SQS_SNS_ENV') ?? env('APP_ENV') ?? '',
        'event_class_postfix' => 'Event'
    ],
]

```

### AWS credentials

[](#aws-credentials)

If we use the same AWS account for SNS than for other AWS services on the application, we can use the default env keys for the credentials.

```
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-west-1

```

If we need specific credentials for SNS, use this env keys:

```
SQS_SNS_ACCESS_KEY_ID=
SQS_SNS_SECRET_ACCESS_KEY=
SQS_SNS_DEFAULT_REGION=eu-west-1

```

### Topics

[](#topics)

The way this library is designed, define SNS topics based on three parts.

[![](https://raw.githubusercontent.com/ralbear/laravel-events-to-sns/docs/media/arn_topic_parts.png)](https://laravel.com)

- A: Use the env variable:

```
SQS_SNS_BASE_ARN=arn:aws:sns:eu-west-1:123456789

```

- B: Defined in your event:

```
public function getTopic()
{
   return 'service-a-topic';
}
```

The event level topics we use, should be defined as a comma separated value on this env variable:

```
SQS_SNS_VALID_TOPICS=service-a-topic,service-b-topic

```

- D: Use the env variable if need a different value than `APP_ENV`:

```
SQS_SNS_ENV=local

```

This `SQS_SNS_ENV` allow us to have custom topics for each environment, if we for example generate new environments for test specific features, we can set here the feature name.

Examples
--------

[](#examples)

### Event example

[](#event-example)

```
