阅读背景:

AWS SNS在laravel-4上实施

来源:互联网 

I am implementing AWS SNS on my project, I am trying to send push notification to Android and iOS device using AWS SNS service, but I am not getting proper document to implement step by step.

我正在我的项目上实现AWS SNS,我正在尝试使用AWS SNS服务向Android和iOS设备发送推送通知,但我没有得到正确的文档来逐步实现。

My code is as follows

我的代码如下

     $aws = Aws::factory(array(
            'profile' => 'my_profile',
            'region'  => 'us-east-1',
            'key'   =>  Config::get('app.aws_access_key'),
            'secret'    =>Config::get('app.aws_secret_access_key')
        ));

   $this->sns = $aws->get('Sns');

   $task = $this->sns->publish(
            array(
                'TargetArn' => 'arn:aws:sns:us-east-1:341707006110:My-topic',
                'Message' => 'Hello from PHP',
                'Subject' => 'Hello world!'
            ));

I am getting the following error:

我收到以下错误:

User: arn:aws:iam::341707006110:user/my-topic is not authorized to perform

用户:arn:aws:iam :: 341707006110:用户/我的主题无权执行

I have a device token like "APA91bGUAbXanTXExEtDpr9XfZE8leNJtB3V" and I want to send push notification on this device. How can I pass device token to publish() method?

我有一个设备令牌,如“APA91bGUAbXanTXExEtDpr9XfZE8leNJtB3V”,我想在此设备上发送推送通知。如何将设备令牌传递给publish()方法?

2 个解决方案

#1


Basically, the issue raises from the fact that your Topic/Target arn is for us-west-2. But by default your SNS client is pointing to us-east-1. You need to call setRegion on snsClient.

基本上,问题来自于你的Topic / Target arn是针对我们 - west-2的事实。但默认情况下,您的SNS客户端指向us-east-1。你需要在snsClient上调用setRegion。

Try after updating the region.

更新区域后尝试。

#2


Looks like your IAM role doesn't have SNS permissions. Try adding them and then try this. In AWS web console goto IAM -> Roles -> select your role -> Attach Policy -> filter using keywords sns, and attach the appropriate policy.

看起来您的IAM角色没有SNS权限。尝试添加它们,然后尝试这个。在AWS Web控制台中转到IAM - >角色 - >选择您的角色 - >附加策略 - >使用关键字sns过滤,并附加相应的策略。


分享到: