AWS-PHP-SDK / SNS direct addressing returns error
Asked Answered
F

1

2

Hi I am using Laravel 4 setup to make use of AWS SNS to send a push message to my iOS device, the publish command to my device works well from AWS console.

I then tried from PHP:

    $sns = AWS::get('sns');

    $sns->publish(array(
        'Message' => 'Hello from PHP',
        'TargetArn' => "arn:aws:sns:us-west-2:360542326270:endpoint/APNS_SANDBOX/Testtest/20a75cd1-da25-3331-8126-4db497cbdd5e"
    ));

I am getting

Guzzle \ Service \ Exception \ ValidationException Validation errors: [TopicArn] is a required string: The topic you want to publish to.

but the docs specifically say I can use publish to either send to a topic ARN or use direct addressing to send to a single device directly.

it seems the AWS PHP SDK forces me to use TopicArn anyway.

http://aws.typepad.com/aws/2013/08/push-notifications-to-mobile-devices-using-amazon-sns.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+AmazonWebServicesBlog+(Amazon+Web+Services+Blog)

what am I doing wrong?

Failing answered 23/4, 2014 at 21:21 Comment(4)
What version of the SDK and Guzzle do you have installed?Fluvial
I ask because I cannot reproduce the error. I copied your code and ran it, but the Guzzle validation succeeds just fine as it should.Fluvial
I have composer doing that for me, I had "guzzle/guzzle": "3.6.*" and now I added "aws/aws-sdk-php-laravel": "1.*". so I got Guzzle 3.6.0 and AWS-PHP-SDK 2.3.4Failing
worked.. see answer belowFailing
F
2

I just removed the explicit guzzle line from composer. then ran update, it removed guzzle 3.6 and installed 3.9. it then removed AWS-PHP-SDK 2.3.4 and installed dev-master

I then tried it and it worked.

not sure what was the problem, but different packages versions did not work together...

Failing answered 25/4, 2014 at 7:11 Comment(2)
The problem is that version 2.3.4 of the SDK did not yet support mobile push notifications, so the TopicArn was required at that time.Fluvial
It's good to explicitly declare your dependencies in your project's composer.json, for example: {"aws/aws-sdk-php-laravel": "~1.1", "aws/aws-sdk-php": "~2.6", "guzzle/guzzle": "~3.9.0"}, and stay up-to-date, especially with the SDK.Fluvial

© 2022 - 2024 — McMap. All rights reserved.