https://github.com/laravel-notification-channels/aws-sns
AWS SNS notification channel for Laravel
https://github.com/laravel-notification-channels/aws-sns
Last synced: 2 months ago
JSON representation
AWS SNS notification channel for Laravel
- Host: GitHub
- URL: https://github.com/laravel-notification-channels/aws-sns
- Owner: laravel-notification-channels
- License: mit
- Created: 2016-08-15T23:43:20.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2025-02-25T01:04:01.000Z (4 months ago)
- Last Synced: 2025-04-04T03:09:46.658Z (3 months ago)
- Language: PHP
- Homepage: https://laravel-notification-channels.com/aws-sns
- Size: 55.7 KB
- Stars: 51
- Watchers: 8
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Amazon Simple Notification Service (AWS SNS) notification channel for Laravel
[](https://packagist.org/packages/laravel-notification-channels/aws-sns)
[](LICENSE.md)
[](https://travis-ci.org/laravel-notification-channels/aws-sns)
[](https://styleci.io/repos/65772445)
[](https://scrutinizer-ci.com/g/laravel-notification-channels/aws-sns)
[](https://scrutinizer-ci.com/g/laravel-notification-channels/aws-sns/?branch=master)
[](https://packagist.org/packages/laravel-notification-channels/aws-sns)This package makes it easy to send notifications using [AWS SNS](https://aws.amazon.com/pt/sns/) with Laravel framework.
Since Laravel already ships with SES email support, this package focuses on sending only SMS notifications for now.
More advanced features like support for topics could be added in the future.## Contents
- [Installation](#installation)
- [Setting up the AwsSns service](#setting-up-the-aws-sns-service)
- [Usage](#usage)
- [Available Message methods](#available-message-methods)
- [Common Problems](#common-problems)
- [Changelog](#changelog)
- [Testing](#testing)
- [Security](#security)
- [Contributing](#contributing)
- [Credits](#credits)
- [License](#license)## Installation
You can install the package via composer:
``` bash
composer require laravel-notification-channels/aws-sns --update-with-dependencies
```### Setting up the AWS SNS service
Add your AWS key ID, secret and default region to your `config/services.php`:
```php
[
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
],];
```## Usage
Now you can use the channel in your `via()` method inside the notification:
```php
service} account was approved!";
// OR explicitly return a SnsMessage object passing the message body:
return new SnsMessage("Your {$notifiable->service} account was approved!");
// OR return a SnsMessage passing the arguments via `create()` or `__construct()`:
return SnsMessage::create([
'body' => "Your {$notifiable->service} account was approved!",
'transactional' => true,
'sender' => 'MyBusiness',
]);// OR create the object with or without arguments and then use the fluent API:
return SnsMessage::create()
->body("Your {$notifiable->service} account was approved!")
->promotional()
->sender('MyBusiness');
}
}
```In order to let your Notification know which phone are you sending to, the channel
will look for the `phone`, `phone_number` or `full_phone` attribute of the
Notifiable model. If you want to override this behaviour, add the
`routeNotificationForSns` method to your Notifiable model.```php
data)
});
```### Lack of Permissions on AWS
By default [Laravel Vapor](https://vapor.laravel.com/) creates the role `laravel-vapor-role` in AWS, which does not have permissions to send SMS via SNS. This results in SMS being sent successfully in local environments but will not be sent on a Vapor environment. Your messages might also not be sent if you are using an ID/Secret pair for a particular IAM user that can't interact with SNS.In either case, you need to make sure the credentials you are using (either your role or user) are allowed to interact with the AWS services your application needs. On IAM (Identity and Access Management), you may attach the AWS Managed policy `AmazonSNSFullAccess` or a more granular custom policy to the role/user your application is using.
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
## Testing
``` bash
$ composer test
```## Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## Credits
- [Claudson Martins](https://github.com/claudsonm)
- [All Contributors](../../contributors)## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.