Skip to content

Commit fa2b228

Browse files
authored
Merge pull request #5 from nipwaayoni/update-documentation
Update documentation
2 parents 90d041f + ad3e24b commit fa2b228

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

README.md

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#Introduction
1+
# Introduction
22
This package provides an easy way of adding AWS SNS message handling to your Laravel application as a REST endpoint. The package can automatically confirm subscription requests and dispatches events when a message is received.
33

4-
##How to create an SNS topic
4+
## How to create an SNS topic
55
[Instructions for creating an SNS topic in AWS can be found here](https://docs.aws.amazon.com/sns/latest/dg/sns-create-topic.html)
66

7-
##How to add SNS Handler to your Application
7+
## How to add SNS Handler to your Application
88
**Note: This package currently requires Laravel >= 8.0. Laravel 7 is no longer supported due to security concerns.**
99

1010
Use composer to require the package:
@@ -13,7 +13,7 @@ Use composer to require the package:
1313
composer require nipwaayoni/laravel-aws-sns
1414
```
1515

16-
##Handling events
16+
## Handling events
1717
Please review the [Laravel documentation on Events.](https://laravel.com/docs/8.x/events) You will need to write a listener to handle the events associated with the ARNs you register. Your listener class must handle the `SnsMessageReceived` event type, which is provided with this package. It should then be registered in the `EventServiceProvider` as mentioned in the Events documentation:
1818
```php
1919
use Nipwaayoni\SnsHandler\Events\SnsMessageReceived;
@@ -25,54 +25,53 @@ use App\Listeners\MySnsMessageHandler;
2525
* @var array
2626
*/
2727
protected $listen = [
28-
SnsMessageReceived::class => [
29-
MySnsMessageHandler::class,
30-
],
28+
SnsMessageReceived::class => [
29+
MySnsMessageHandler::class,
30+
],
3131
];
32-
In your listener, the handle method will receive an SnsMessageReceived object which can be used to access the SnsMessage.
33-
32+
```
33+
In your listener, the handle method will receive an SnsMessageReceived object which can be used to access the SnsMessage.
34+
```php
3435
public function handle(SnsMessageReceived $event)
3536
{
36-
$message = $event->message();
37-
38-
// do stuff with message
39-
$content = $message->content();
37+
$message = $event->message();
38+
// do stuff with message
39+
$content = $message->content();
4040
}
4141
```
4242
The message content will always be a string. You are responsible for any deserialization or other steps required to interpret the message content.
4343

44-
##Write a feature test to test the expected SNS feature
44+
## Write a feature test to test the expected SNS feature
4545
The ReceivesSnsMessagesTrait facilitates testing. Use the trait in your test
4646

4747
Sample test:
4848
```php
4949
public function testSnsRequestMapping(): void
5050
{
51-
Bus::fake();
52-
$data = "Bob";
53-
$this->sendSnsMessage($data);
54-
55-
Bus::assertDispatched(SayHelloJob::class);
56-
57-
}
51+
Bus::fake();
52+
$data = "Bob";
53+
$this->sendSnsMessage($data);
54+
Bus::assertDispatched(SayHelloJob::class);
55+
}
5856
```
5957
Disable message signature validation when sending events from sources other than SNS (and during feature tests). Add to .env:
6058
```
6159
VALIDATE_SNS_MESSAGES=false
6260
```
6361

64-
##How do I send SNS messages to my app?
62+
## How do I send SNS messages to my app?
6563
The SNS message route responds to POST requests and expects content consistent with an SNS message from AWS.
6664

6765
The message content of an SNS message must be provided as a string value. If your payload is something other than a simple string (e.g. an array or some other sort of object), you will need to serialize your data before sending it using something like json_encode().
6866

69-
###POSTing directly to your app
67+
### POSTing directly to your app
7068
[Amazon has an example of a POST request available here.](https://docs.aws.amazon.com/sns/latest/dg/sns-http-https-endpoint-as-subscriber.html)
7169
You can add your serialized message in the message field. Note that manually POSTed messages cannot be validated (See above to disable message validation). We recommend only attempting this during testing, never in your production environment.
7270

7371

74-
##How to subscribe your endpoint in AWS
75-
[Follow these instructions to subscribe your endpoint using HTTPS](https://docs.aws.amazon.com/sns/latest/dg/sns-http-https-endpoint-as-subscriber.html)
72+
## How to subscribe your endpoint in AWS
73+
This package adds a route to your application for incoming SNS requests. Note that because this is an api route, any API middleware you have applied in your application will affect this route. The route will be `{Your application's base URL}/api/sns/message`.
74+
[Follow these instructions to subscribe your endpoint using HTTPS](https://docs.aws.amazon.com/sns/latest/dg/sns-http-https-endpoint-as-subscriber.html).
7675

7776
**Note: You will only be able to subscribe your endpoint if it can be reached from the AWS SNS service**
7877

0 commit comments

Comments
 (0)