I have a requirement, where I want to add number (UNIX timestamp) filter policy to device subscription, and while publishing a notification to the topic add message attributes with range policy, but I get internal server response from AWS SDK.
Here is what I'm doing while publishing a message to device subscribed 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 fine, but subscribing a device to SNS topic and setting subscription attributes gives 500 response code 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 response 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"