descom/aws-sns-notification

Package to Laravel to received notification from AWS SNS

1.1.0 2024-04-18 14:54 UTC

This package is auto-updated.

Last update: 2024-04-18 14:54:53 UTC


README

tests analyze style

Install

composer require descom/aws-sns-notifications

Usage

Create en SNS a subscription HTTPS to a topic

https://localhost:8000/aws/sns/webhook

Capture Events

AwsSnsSubscriptionConfirmationReceived

use Descom\AwsSnsNotification\Events\TopicSubscriptionRequest;
use Illuminate\Support\Facades\Http;

class SnsSubscriptionConfirmation
{
    public function handle(TopicSubscriptionRequest $event): void
    {
        // Confirm the subscription by sending a GET request to the SubscribeURL

        Http::get($event->subscribeUrl());
    }
}

AwsSnsNotificationReceived

use Descom\AwsSnsNotification\Events\TopicNotification;
use Illuminate\Support\Facades\Http;

class SnsNotificationLogger
{
    public function handle(TopicNotification $event): void
    {
        logger()->info('SNS Notification received', [
            'topic' => $event->topicArn(),
            'subject' => $event->subject(),
            'message' => $event->toJson(),
        ]);
    }
}