Skip to content

Commit

Permalink
v1
Browse files Browse the repository at this point in the history
  • Loading branch information
introwit committed Nov 18, 2019
1 parent b8a95ff commit a4d17c0
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Laravel package for the AWS SNS Events

[![Latest Version](https://img.shields.io/github/release/JoggApp/laravel-aws-sns.svg?style=flat-rounded)](https://github.com/JoggApp/laravel-aws-sns/releases)
[![Total Downloads](https://img.shields.io/packagist/dt/JoggApp/laravel-aws-sns.svg?style=flat-rounded&colorB=brightgreen)](https://packagist.org/packages/JoggApp/laravel-aws-sns)

Amazon Simple Notification Service (Amazon SNS) is a web service that coordinates and manages the delivery or sending of messages to subscribing endpoints or clients. The Amazon S3 notification feature enables you to receive notifications when certain events happen in your bucket.

This package ships with a controller that listens to the SNS notification incoming to one of your defined URL/endpoint. The controller takes care of validating the incoming request's signature & messages, confirming your endpoint's subscription to the SNS topic and also emits respective Laravel events. If you are using AWS SNS, all you have to do after installing this package is add your desired Laravel Listeners. The Listeners will automatically receive the SNS message. You are free to take control of the message after that to achieve your desired results.

## Installation and Usage

- You can install this package via composer using this command:

```bash
composer require joggapp/laravel-aws-sns
```

- The package will automatically register itself.

- You can assign the AwsSnsController to any of your desired routes. The AwsSnsController is a single action controller, so all you have to assign is just the controller class to the route. Eg:

```php
use JoggApp\AwsSns\Controllers\AwsSnsController;

...

Route::post('webhooks/aws/sns', AwsSnsController::class);
```

- The package emits 2 events: `SnsTopicSubscriptionConfirmed` & `SnsMessageReceived`.

- `SnsTopicSubscriptionConfirmed`: This event is fired once the endpoint's subscription to the SNS topic is confirmed.

- `SnsMessageReceived`: This event is fired everytime your endpoint receives a message (request) from AWS SNS.

- To use these events you will have to add the events in your `app/Providers/EventServiceProvider.php`

- You can access the SNS message in your listeners listening to the `SnsMessageReceived` event just like you would do in any other laravel listener:

```php
class SnsListener
{
public function handle($event)
{
$event->message
}
}
```

## Changelog

Please see the [CHANGELOG](CHANGELOG.md) for more information about what has changed recently.

## Security

If you discover any security related issues, please email them to [[email protected]](mailto:[email protected]) instead of using the issue tracker.

## Credits

- [Harish Toshniwal](https://github.com/introwit)
- [All Contributors](../../contributors)

## License

The MIT License (MIT). Please see the [License File](LICENSE.txt) for more information.
4 changes: 2 additions & 2 deletions src/Controllers/AwsSnsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Aws\Sns\Exception\InvalidSnsMessageException;
use Aws\Sns\Message;
use Aws\Sns\MessageValidator;
use JoggApp\AwsSns\Events\SnsEventReceived;
use JoggApp\AwsSns\Events\SnsMessageReceived;
use JoggApp\AwsSns\Events\SnsTopicSubscriptionConfirmed;

class AwsSnsController
Expand Down Expand Up @@ -33,7 +33,7 @@ public function __invoke()
}

if (isset($message['Type']) && $message['Type'] === 'Notification') {
event(new SnsEventReceived($message));
event(new SnsMessageReceived($message));
}

return response('OK', 200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Aws\Sns\Message;
use Illuminate\Queue\SerializesModels;

class SnsEventReceived
class SnsMessageReceived
{
use SerializesModels;

Expand Down

0 comments on commit a4d17c0

Please sign in to comment.