├── .gitignore ├── CHANGELOG.md ├── LICENSE.txt ├── README.md ├── composer.json └── src ├── AwsSnsServiceProvider.php ├── Controllers └── AwsSnsController.php └── Events ├── SnsMessageReceived.php └── SnsTopicSubscriptionConfirmed.php /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.lock 3 | .DS_Store 4 | Thumbs.db 5 | phpunit.xml 6 | /.idea -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | All the notable changes to the Laravel Aws Sns package are documented in this file: 2 | 3 | ## v7.0.0 (13-03-2024) 4 | - min php 8.2 5 | - laravel v11 support 6 | 7 | ## v4.0.1 (16-02-2022) 8 | - improve version constraints 9 | 10 | ## v4.0.0 (11-02-2022) 11 | - Added Laravel 9 support and dropped support for Laravel 7 and 8, and PHP 7. 12 | 13 | ## v3.0.1 (06-01-2021) 14 | - Added PHP 8 support. 15 | 16 | ## v3.0.0 (10-09-2020) 17 | - Added Laravel v8.x support. 18 | - Dropped Laravel v6.x support. 19 | 20 | ## v2.0.0 (03-03-2020) 21 | - Added Laravel v7.x support. 22 | - Dropped PHP v7.2 support, now PHP v7.3 is the minimum requirement. 23 | 24 | ## v1.0.1 (20-11-2019) 25 | - Added `awsSnsWebhooks` route helper 26 | 27 | ## v1.0.0 (18-11-2019) 28 | - Initial release 29 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Jogg Inc 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 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 then need to pass the route to `awsSnsWebhooks`: 21 | 22 | ```php 23 | Route::awsSnsWebhooks('route-you-added-in-aws-sns-topic-subscription-console'); 24 | ``` 25 | 26 | - The package emits 2 events: `SnsTopicSubscriptionConfirmed` & `SnsMessageReceived`. 27 | 28 | - `SnsTopicSubscriptionConfirmed`: This event is fired once the endpoint's subscription to the SNS topic is confirmed. 29 | 30 | - `SnsMessageReceived`: This event is fired everytime your endpoint receives a message (request) from AWS SNS. 31 | 32 | - To use these events you will have to add the events in your `app/Providers/EventServiceProvider.php` 33 | 34 | - You can access the SNS message in your listeners listening to the `SnsMessageReceived` event just like you would do in any other laravel listener: 35 | 36 | ```php 37 | class SnsListener 38 | { 39 | public function handle($event) 40 | { 41 | $event->message 42 | } 43 | } 44 | ``` 45 | 46 | ## Changelog 47 | 48 | Please see the [CHANGELOG](CHANGELOG.md) for more information about what has changed recently. 49 | 50 | ## Security 51 | 52 | If you discover any security related issues, please email them to [harish@jogg.co](mailto:harish@jogg.co) instead of using the issue tracker. 53 | 54 | ## Credits 55 | 56 | - [Harish Toshniwal](https://github.com/introwit) 57 | - [All Contributors](../../contributors) 58 | 59 | ## License 60 | 61 | The MIT License (MIT). Please see the [License File](LICENSE.txt) for more information. 62 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "joggapp/laravel-aws-sns", 3 | "description": "Laravel package for the SNS events by AWS", 4 | "keywords": [ 5 | "laravel", 6 | "package", 7 | "aws", 8 | "sns", 9 | "aws sns", 10 | "aws sns events" 11 | ], 12 | "license": "MIT", 13 | "authors": [ 14 | { 15 | "name": "Harish Toshniwal", 16 | "email": "harish@jogg.co" 17 | } 18 | ], 19 | "autoload": { 20 | "psr-4": { 21 | "JoggApp\\AwsSns\\": "src" 22 | } 23 | }, 24 | "require": { 25 | "php": "^8.3", 26 | "aws/aws-php-sns-message-validator": "^1.6", 27 | "illuminate/http": "^12.0", 28 | "illuminate/queue": "^12.0", 29 | "illuminate/support": "^12.0" 30 | }, 31 | "extra": { 32 | "laravel": { 33 | "providers": [ 34 | "JoggApp\\AwsSns\\AwsSnsServiceProvider" 35 | ], 36 | "aliases":{ 37 | "AwsSns": "JoggApp\\AwsSns\\AwsSnsFacade" 38 | } 39 | } 40 | }, 41 | "config": { 42 | "sort-packages": true 43 | }, 44 | "minimum-stability": "dev", 45 | "prefer-stable": true 46 | } 47 | -------------------------------------------------------------------------------- /src/AwsSnsServiceProvider.php: -------------------------------------------------------------------------------- 1 | body(); 22 | }); 23 | }); 24 | 25 | try { 26 | $validator->validate($message); 27 | } catch (InvalidSnsMessageException $e) { 28 | // Return 404 to pretend we are not here for SNS if invalid request 29 | return response('SNS Message Validation Error: ' . $e->getMessage(), 404); 30 | } 31 | 32 | if (isset($message['Type']) && $message['Type'] === 'SubscriptionConfirmation') { 33 | // Confirm the subscription by sending a GET request to the SubscribeURL 34 | Http::get($message['SubscribeURL']); 35 | 36 | event(new SnsTopicSubscriptionConfirmed); 37 | 38 | return response('OK', 200); 39 | } 40 | 41 | if (isset($message['Type']) && $message['Type'] === 'Notification') { 42 | event(new SnsMessageReceived($message)); 43 | } 44 | 45 | return response('OK', 200); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Events/SnsMessageReceived.php: -------------------------------------------------------------------------------- 1 | message = $message; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Events/SnsTopicSubscriptionConfirmed.php: -------------------------------------------------------------------------------- 1 |