Php aws sns subscription with a numerical filter policy and sending notifications to subscribers in the range

I have a requirement when I want to add a quantity filter policy (UNIX timestamp) to a device subscription, and when I post a notification in the subject, add message attributes with a range policy, but I get an internal server response from the AWS SDK.

Here's what I do by posting a message to a device signed at a specific time,

$filterMessageAttributes = [
                "DataType" => "Binary",
                "BinaryValue" => json_encode([
                    "numeric" => [
                        ">=",
                        $filterStartUnixTime,
                        "<=",
                        $filterEndUnixTime
                    ]
                ])
            ];
$res =  $sns->publish([
                'Message' => json_encode($message),
                'TopicArn' => $appTopicARN,
                'MessageStructure' => 'json',
                'MessageAttributes' => [
                    "subscription_timestamp" =>  $filterMessageAttributes
                ]
            ]);

This works great, but subscribing to an SNS topic and setting subscription attributes gives 500 responses from AWS

$res = $sns->createPlatformEndpoint([
                "PlatformApplicationArn" => "<android app arn>",
                "Token" => "<device token>",
                "CustomUserData" => "<some user attributes>"
            ]);
$endPointARN = $res->get("EndpointArn");
$res = $sns->subscribe([
        "TopicArn" => "<android topic arn>",
        "Protocol" => "application",
        "Endpoint" => $endPointARN
       ]);
/**
 * Add unix timestamp attribute  to the above subscription
 */
$sns->setSubscriptionAttributes([
     // SubscriptionArn is required
     'SubscriptionArn' => $res->get("SubscriptionArn"),
     // AttributeName is required
     'AttributeName' => 'FilterPolicy',
     'AttributeValue' => json_encode([
     "subscription_timestamp" => [time()]
     ])]);

Below is the answer from AWS,

Error executing "SetSubscriptionAttributes" on "https://sns.us-west-2.amazonaws.com"; AWS HTTP error: Server error: `POST https://sns.us-west-2.amazonaws.com` resulted in a `500 Internal Server Error` response: <ErrorResponse xmlns="http://sns.amazonaws.com/doc/2010-03-31/">   <Error>     <Type>Receiver</Type>     <Code>InternalF (truncated...)  InternalFailure (server):  - <ErrorResponse xmlns="http://sns.amazonaws.com/doc/2010-03-31/">   <Error>     <Type>Receiver</Type>     <Code>InternalFailure</Code>   </Error>   <RequestId><REQUESTID></RequestId> </ErrorResponse>

PHP AWS SDK Version: "3.52.31"

+4
source share

Source: https://habr.com/ru/post/1696313/


All Articles