An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

        

# Amazon Simple Notification Service (AWS SNS) notification channel for Laravel

[![Latest Version on Packagist](https://img.shields.io/packagist/v/laravel-notification-channels/aws-sns.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/aws-sns)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Build Status](https://img.shields.io/travis/laravel-notification-channels/aws-sns/master.svg?style=flat-square)](https://travis-ci.org/laravel-notification-channels/aws-sns)
[![StyleCI](https://styleci.io/repos/65772445/shield)](https://styleci.io/repos/65772445)
[![Quality Score](https://img.shields.io/scrutinizer/g/laravel-notification-channels/aws-sns.svg?style=flat-square)](https://scrutinizer-ci.com/g/laravel-notification-channels/aws-sns)
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/laravel-notification-channels/aws-sns/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/laravel-notification-channels/aws-sns/?branch=master)
[![Total Downloads](https://img.shields.io/packagist/dt/laravel-notification-channels/aws-sns.svg?style=flat-square)](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.