Last active
October 23, 2016 06:47
-
-
Save appkr/699552c5aca4c05138f9f36718ecad11 to your computer and use it in GitHub Desktop.
AWS SNS in Laravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Install SDK | |
| // https://github.com/aws/aws-sdk-php-laravel | |
| Route::post('sns', function(\Illuminate\Http\Request $request) { | |
| $message = json_decode($request->getContent())->Message; | |
| Log::info([$request->header('content-type'), $message]); | |
| // do some job. | |
| return response('', 204); | |
| }); | |
| //Line 3 generates the following | |
| //[2016-10-23 06:41:39] local.INFO: array ( | |
| // 0 => 'text/plain; charset=UTF-8', | |
| // 1 => '{"type":"updated","model":"store","entries":[1,2,3,4,5]}', | |
| //) | |
| Route::get('sns', function () { | |
| $topicArn = 'arn:aws:sns:ap-northeast-2:xxxxxxxxxxxx:topic-name'; | |
| $sns = app('aws')->createClient('sns'); | |
| // publish new message | |
| return $sns->publish([ | |
| 'TopicArn' => $topicArn, | |
| 'Message' => json_encode([ | |
| 'default' => 'default', | |
| 'http' => json_encode([ | |
| 'type' => 'updated', | |
| 'model' => 'store', | |
| 'entries' => [1,2,3,4,5] | |
| ]) | |
| ]), | |
| 'MessageStructure' => 'json', | |
| ])->toArray(); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment