Skip to content

Commit

Permalink
feat: ensure/automatically confirm the SNS subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbbreuer committed Mar 22, 2021
1 parent cf64766 commit 352566b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ Finally, we need to confirm the subscription which is easily done by navigating

![AWS SNS Subscription Confirmation Screenshot](https://i.imgur.com/qzLZJAD.png)

By default, AWS will have sent a post request to URL you defined in your "Subscription" setup. You can view request in the Expose interface, by visiting the "Dashboard Url", which should be similar to: `http://127.0.0.1:4040`
By default, AWS will have sent a post request to URL you defined in your "Subscription" setup. This package automatically handles the "confirmation" part. In case there is an issue and it is not confirmed yet, please click on the "Request confirmation" button as seen in the screenshot above.

Once you are in the Expose dashboard, you need to locate the `SubscribeURL` value. Once located, copy it and use it to confirm your SNS Topic Subscription.
You can also view the request in the Expose interface, by visiting the "Dashboard Url", which should be similar to: `http://127.0.0.1:4040`

![AWS SNS Subscription Confirmation Screenshot](https://i.imgur.com/ECGIBUY.png)
Once the status reflects "Confirmed", your API will receive webhooks as AWS provides updates.

#### Create CloudWatch Event

Expand Down
18 changes: 17 additions & 1 deletion src/Http/Controllers/IncomingWebhookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Aws\Sns\Message;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Http;
use Meema\MediaConverter\Events\ConversionHasCompleted;
use Meema\MediaConverter\Events\ConversionHasError;
use Meema\MediaConverter\Events\ConversionHasInputInformation;
Expand All @@ -25,7 +26,8 @@ public function __construct()
public function __invoke()
{
try {
$message = json_decode(Message::fromRawPostData()['Message'] ?? '', true);
$message = $this->ensureSubscriptionIsConfirmed();

$detail = $message['detail'];
$status = $detail['status'];

Expand Down Expand Up @@ -68,4 +70,18 @@ public function fireEventFor($status, $message)
throw new \Exception();
}
}

/**
* @return array
*/
public function ensureSubscriptionIsConfirmed(): array
{
$message = Message::fromRawPostData()->toArray();

if (array_key_exists('SubscribeURL', $message)) {
Http::get($message['SubscribeURL']);
}

return $message;
}
}

0 comments on commit 352566b

Please sign in to comment.