Skip to content

Commit a4d17c0

Browse files
committed
v1
1 parent b8a95ff commit a4d17c0

File tree

3 files changed

+68
-3
lines changed

3 files changed

+68
-3
lines changed

README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Laravel package for the AWS SNS Events
2+
3+
[![Latest Version](https://img.shields.io/github/release/JoggApp/laravel-aws-sns.svg?style=flat-rounded)](https://github.com/JoggApp/laravel-aws-sns/releases)
4+
[![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)
5+
6+
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.
7+
8+
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.
9+
10+
## Installation and Usage
11+
12+
- You can install this package via composer using this command:
13+
14+
```bash
15+
composer require joggapp/laravel-aws-sns
16+
```
17+
18+
- The package will automatically register itself.
19+
20+
- 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:
21+
22+
```php
23+
use JoggApp\AwsSns\Controllers\AwsSnsController;
24+
25+
...
26+
27+
Route::post('webhooks/aws/sns', AwsSnsController::class);
28+
```
29+
30+
- The package emits 2 events: `SnsTopicSubscriptionConfirmed` & `SnsMessageReceived`.
31+
32+
- `SnsTopicSubscriptionConfirmed`: This event is fired once the endpoint's subscription to the SNS topic is confirmed.
33+
34+
- `SnsMessageReceived`: This event is fired everytime your endpoint receives a message (request) from AWS SNS.
35+
36+
- To use these events you will have to add the events in your `app/Providers/EventServiceProvider.php`
37+
38+
- You can access the SNS message in your listeners listening to the `SnsMessageReceived` event just like you would do in any other laravel listener:
39+
40+
```php
41+
class SnsListener
42+
{
43+
public function handle($event)
44+
{
45+
$event->message
46+
}
47+
}
48+
```
49+
50+
## Changelog
51+
52+
Please see the [CHANGELOG](CHANGELOG.md) for more information about what has changed recently.
53+
54+
## Security
55+
56+
If you discover any security related issues, please email them to [[email protected]](mailto:[email protected]) instead of using the issue tracker.
57+
58+
## Credits
59+
60+
- [Harish Toshniwal](https://github.com/introwit)
61+
- [All Contributors](../../contributors)
62+
63+
## License
64+
65+
The MIT License (MIT). Please see the [License File](LICENSE.txt) for more information.

src/Controllers/AwsSnsController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Aws\Sns\Exception\InvalidSnsMessageException;
66
use Aws\Sns\Message;
77
use Aws\Sns\MessageValidator;
8-
use JoggApp\AwsSns\Events\SnsEventReceived;
8+
use JoggApp\AwsSns\Events\SnsMessageReceived;
99
use JoggApp\AwsSns\Events\SnsTopicSubscriptionConfirmed;
1010

1111
class AwsSnsController
@@ -33,7 +33,7 @@ public function __invoke()
3333
}
3434

3535
if (isset($message['Type']) && $message['Type'] === 'Notification') {
36-
event(new SnsEventReceived($message));
36+
event(new SnsMessageReceived($message));
3737
}
3838

3939
return response('OK', 200);

src/Events/SnsEventReceived.php renamed to src/Events/SnsMessageReceived.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Aws\Sns\Message;
66
use Illuminate\Queue\SerializesModels;
77

8-
class SnsEventReceived
8+
class SnsMessageReceived
99
{
1010
use SerializesModels;
1111

0 commit comments

Comments
 (0)