### Install AsyncAws Sns Client Source: https://github.com/async-aws/sns/blob/master/README.md Use this command to install the AsyncAws Sns Client using Composer. ```cli composer require async-aws/sns ``` -------------------------------- ### Client Instantiation Source: https://context7.com/async-aws/sns/llms.txt Instantiate SnsClient with optional configuration, credential provider, and HTTP client. When no arguments are given, the client reads credentials from environment variables or the default AWS credential chain. ```APIDOC ## Client Instantiation Instantiate `SnsClient` with optional configuration, credential provider, and HTTP client. When no arguments are given, the client reads credentials from environment variables or the default AWS credential chain. ```php use AsyncAws\Sns\SnsClient; // Default: credentials from environment / IAM role $sns = new SnsClient(['region' => 'us-east-1']); // Explicit credentials $sns = new SnsClient([ 'region' => 'eu-west-1', 'accessKeyId' => 'AKIAIOSFODNN7EXAMPLE', 'accessKeySecret' => 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY', ]); // FIPS endpoint $sns = new SnsClient(['region' => 'fips-us-east-1']); ``` ``` -------------------------------- ### Instantiate SnsClient Source: https://context7.com/async-aws/sns/llms.txt Instantiate the SnsClient with optional configuration. By default, it reads credentials from environment variables or the AWS credential chain. Supports specifying region, access keys, and FIPS endpoints. ```php use AsyncAws\Sns\SnsClient; // Default: credentials from environment / IAM role $sns = new SnsClient(['region' => 'us-east-1']); // Explicit credentials $sns = new SnsClient([ 'region' => 'eu-west-1', 'accessKeyId' => 'AKIAIOSFODNN7EXAMPLE', 'accessKeySecret' => 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY', ]); // FIPS endpoint $sns = new SnsClient(['region' => 'fips-us-east-1']); ``` -------------------------------- ### List All SNS Topics (Paginated) Source: https://context7.com/async-aws/sns/llms.txt Retrieves a list of SNS topics, supporting automatic pagination for iterating through all topics. Throttled at 30 TPS. ```php use AsyncAws\Sns\SnsClient; $sns = new SnsClient(['region' => 'us-east-1']); // --- Iterate all topics across all pages automatically --- $result = $sns->listTopics(); foreach ($result as $topic) { echo "Topic ARN: " . $topic->getTopicArn() . "\n"; } // --- Current page only (manual pagination) --- $result = $sns->listTopics(); foreach ($result->getTopics(true) as $topic) { echo $topic->getTopicArn() . "\n"; } $nextToken = $result->getNextToken(); if ($nextToken !== null) { $nextPage = $sns->listTopics(['NextToken' => $nextToken]); foreach ($nextPage->getTopics(true) as $topic) { echo $topic->getTopicArn() . "\n"; } } ``` -------------------------------- ### List All Topics Source: https://context7.com/async-aws/sns/llms.txt Returns a paginated list of all topics. Supports auto-pagination for iterating through all topics across all pages. ```APIDOC ## `listTopics` — List All Topics (Paginated) ### Description Returns up to 100 topics per page. The result implements `IteratorAggregate`, automatically fetching all pages when iterated without `$currentPageOnly = true`. Throttled at 30 TPS. ### Method POST ### Endpoint / ### Parameters #### Query Parameters - **NextToken** (string) - Optional - The token returned from a previous request to retrieve the next page of results. - **MaxResults** (integer) - Optional - The maximum number of topics to return per page. ### Response #### Success Response (200) - **Topics** (array) - A list of topics. Each topic object contains: - **TopicArn** (string) - The ARN of the topic. - **NextToken** (string) - The token to retrieve the next page of results, or null if there are no more pages. ``` -------------------------------- ### createTopic Source: https://context7.com/async-aws/sns/llms.txt Creates a standard or FIFO SNS topic. The operation is idempotent: if a topic with the given name already exists its ARN is returned. FIFO topic names must end with `.fifo`. ```APIDOC ## `createTopic` — Create an SNS Topic Creates a standard or FIFO SNS topic. The operation is idempotent: if a topic with the given name already exists its ARN is returned. FIFO topic names must end with `.fifo`. ```php use AsyncAws\Sns\SnsClient; use AsyncAws\Sns\ValueObject\Tag; use AsyncAws\Sns\Exception\TopicLimitExceededException; $sns = new SnsClient(['region' => 'us-east-1']); // Standard topic with display name and tags try { $response = $sns->createTopic([ 'Name' => 'order-notifications', 'Attributes' => [ 'DisplayName' => 'Order Notifications', ], 'Tags' => [ ['Key' => 'Environment', 'Value' => 'production'], ['Key' => 'Team', 'Value' => 'backend'], ], ]); $topicArn = $response->getTopicArn(); // e.g. "arn:aws:sns:us-east-1:123456789012:order-notifications" echo "Topic ARN: $topicArn\n"; } catch (TopicLimitExceededException $e) { echo "Topic limit reached: " . $e->getMessage() . "\n"; } // FIFO topic with content-based deduplication $fifoResponse = $sns->createTopic([ 'Name' => 'inventory-updates.fifo', 'Attributes' => [ 'FifoTopic' => 'true', 'ContentBasedDeduplication' => 'true', ], ]); echo "FIFO Topic ARN: " . $fifoResponse->getTopicArn() . "\n"; ``` ``` -------------------------------- ### Create SNS Topic Source: https://context7.com/async-aws/sns/llms.txt Creates a standard or FIFO SNS topic. The operation is idempotent. FIFO topic names must end with '.fifo'. Supports setting display name, attributes like FifoTopic and ContentBasedDeduplication, and tags. ```php use AsyncAws\Sns\SnsClient; use AsyncAws\Sns\ValueObject\Tag; use AsyncAws\Sns\Exception\TopicLimitExceededException; $sns = new SnsClient(['region' => 'us-east-1']); // Standard topic with display name and tags try { $response = $sns->createTopic([ 'Name' => 'order-notifications', 'Attributes' => [ 'DisplayName' => 'Order Notifications', ], 'Tags' => [ ['Key' => 'Environment', 'Value' => 'production'], ['Key' => 'Team', 'Value' => 'backend'], ], ]); $topicArn = $response->getTopicArn(); // e.g. "arn:aws:sns:us-east-1:123456789012:order-notifications" echo "Topic ARN: $topicArn\n"; } catch (TopicLimitExceededException $e) { echo "Topic limit reached: " . $e->getMessage() . "\n"; } // FIFO topic with content-based deduplication $fifoResponse = $sns->createTopic([ 'Name' => 'inventory-updates.fifo', 'Attributes' => [ 'FifoTopic' => 'true', 'ContentBasedDeduplication' => 'true', ], ]); echo "FIFO Topic ARN: " . $fifoResponse->getTopicArn() . "\n"; ``` -------------------------------- ### createPlatformEndpoint Source: https://context7.com/async-aws/sns/llms.txt Registers a mobile device for push notifications on platforms like APNs or FCM. This operation is idempotent. ```APIDOC ## `createPlatformEndpoint` — Register a Mobile Device for Push Notifications Creates an endpoint for a device and app on a push notification platform (APNs, FCM/GCM). Requires a `PlatformApplicationArn` from `CreatePlatformApplication`. The operation is idempotent — if an endpoint with the same token and attributes already exists, its ARN is returned. ### Method POST ### Endpoint / ### Parameters #### Query Parameters - **Action** (string) - Required - `CreatePlatformEndpoint` - **Version** (string) - Required - `2010-03-31` #### Request Body - **PlatformApplicationArn** (string) - Required - The ARN of the platform application. - **Token** (string) - Required - The identifier for the device token. - **CustomUserData** (string) - Optional - Arbitrary user data to associate with the endpoint. - **Attributes** (object) - Optional - A map of attributes to set on the endpoint. - **Enabled** (string) - Optional - Set to `true` to enable the endpoint, `false` to disable. ### Request Example ```json { "PlatformApplicationArn": "arn:aws:sns:us-east-1:123456789012:app/GCM/MyAndroidApp", "Token": "APA91bHPRgkFzRisjVDSBQMmWEehy2zXx...", "CustomUserData": "{\"userId\": \"user-789\", \"deviceType\": \"android\"}", "Attributes": { "Enabled": "true" } } ``` ### Response #### Success Response (200) - **CreatePlatformEndpointResult** (object) - **EndpointArn** (string) - The ARN of the created endpoint. #### Response Example ```json { "CreatePlatformEndpointResult": { "EndpointArn": "arn:aws:sns:us-east-1:123456789012:endpoint/GCM/MyAndroidApp/abc123..." } } ``` ``` -------------------------------- ### Create Platform Endpoint for Push Notifications Source: https://context7.com/async-aws/sns/llms.txt Registers a device for push notifications on platforms like APNs or FCM. The operation is idempotent. Ensure you have a `PlatformApplicationArn` from `CreatePlatformApplication`. ```php use AsyncAws\Sns\SnsClient; use AsyncAws\Sns\Exception\InvalidParameterException; $sns = new SnsClient(['region' => 'us-east-1']); // Register an FCM (Firebase Cloud Messaging) device token try { $response = $sns->createPlatformEndpoint([ 'PlatformApplicationArn' => 'arn:aws:sns:us-east-1:123456789012:app/GCM/MyAndroidApp', 'Token' => 'APA91bHPRgkFzRisjVDSBQMmWEehy2zXx...', // FCM registration token 'CustomUserData' => json_encode(['userId' => 'user-789', 'deviceType' => 'android']), 'Attributes' => [ 'Enabled' => 'true', ], ]); $endpointArn = $response->getEndpointArn(); // e.g. "arn:aws:sns:us-east-1:123456789012:endpoint/GCM/MyAndroidApp/abc123..." echo "Endpoint ARN: $endpointArn\n"; // Use the endpoint ARN to send a direct push notification $pushResponse = $sns->publish([ 'TargetArn' => $endpointArn, 'Message' => json_encode([ 'GCM' => json_encode([ 'notification' => [ 'title' => 'New message', 'body' => 'You have 3 unread messages.', ], ]), ]), 'MessageStructure' => 'json', ]); echo "Push MessageId: " . $pushResponse->getMessageId() . "\n"; } catch (InvalidParameterException $e) { echo "Invalid platform endpoint parameter: " . $e->getMessage() . "\n"; } ``` -------------------------------- ### List SNS Subscriptions for a Topic (Paginated) Source: https://context7.com/async-aws/sns/llms.txt Lists subscriptions for a specific SNS topic, supporting auto-pagination. Each subscription object provides details like protocol, endpoint, and ARN. ```php use AsyncAws\Sns\SnsClient; $sns = new SnsClient(['region' => 'us-east-1']); $topicArn = 'arn:aws:sns:us-east-1:123456789012:order-notifications'; // Auto-paginated iteration over all subscriptions $result = $sns->listSubscriptionsByTopic(['TopicArn' => $topicArn]); foreach ($result as $subscription) { printf( "Protocol: %-12s Endpoint: %s\n", $subscription->getProtocol(), $subscription->getEndpoint() ); } // Current page only, collecting into an array $subscriptions = iterator_to_array( $sns->listSubscriptionsByTopic(['TopicArn' => $topicArn])->getSubscriptions(true) ); echo "Subscriptions on first page: " . count($subscriptions) . "\n"; ``` -------------------------------- ### List Subscriptions for a Topic Source: https://context7.com/async-aws/sns/llms.txt Returns a paginated list of subscriptions for a specific topic. Supports auto-pagination for iterating through all subscriptions. ```APIDOC ## `listSubscriptionsByTopic` — List Subscriptions for a Topic (Paginated) ### Description Returns up to 100 subscriptions per page for a specific topic. Supports auto-pagination via iterator. Each `Subscription` value object exposes `getSubscriptionArn()`, `getProtocol()`, `getEndpoint()`, `getOwner()`, and `getTopicArn()`. ### Method POST ### Endpoint / ### Parameters #### Query Parameters - **TopicArn** (string) - Required - The ARN of the topic for which to list subscriptions. - **NextToken** (string) - Optional - The token returned from a previous request to retrieve the next page of results. - **MaxResults** (integer) - Optional - The maximum number of subscriptions to return per page. ### Response #### Success Response (200) - **Subscriptions** (array) - A list of subscriptions. Each subscription object contains: - **SubscriptionArn** (string) - The ARN of the subscription. - **Protocol** (string) - The protocol of the subscription. - **Endpoint** (string) - The endpoint of the subscription. - **Owner** (string) - The owner of the subscription. - **TopicArn** (string) - The ARN of the topic. - **NextToken** (string) - The token to retrieve the next page of results, or null if there are no more pages. ``` -------------------------------- ### Publish Up to 10 Messages in a Single Request Source: https://context7.com/async-aws/sns/llms.txt Use this for sending multiple messages efficiently in one API call. Always check the `getFailed()` results for any messages that did not succeed, even if the overall HTTP status is 200. ```php use AsyncAws\Sns\SnsClient; use AsyncAws\Sns\ValueObject\PublishBatchRequestEntry; use AsyncAws\Sns\Exception\BatchRequestTooLongException; $sns = new SnsClient(['region' => 'us-east-1']); $entries = [ new PublishBatchRequestEntry([ 'Id' => 'msg-1', 'Message' => json_encode(['event' => 'user.signup', 'userId' => 101]), 'Subject' => 'User Signup', ]), new PublishBatchRequestEntry([ 'Id' => 'msg-2', 'Message' => json_encode(['event' => 'user.verified', 'userId' => 102]), 'Subject' => 'User Verified', ]), new PublishBatchRequestEntry([ 'Id' => 'msg-3', 'Message' => json_encode(['event' => 'user.deleted', 'userId' => 103]), 'Subject' => 'User Deleted', ]), ]; try { $response = $sns->publishBatch([ 'TopicArn' => 'arn:aws:sns:us-east-1:123456789012:user-events', 'PublishBatchRequestEntries' => $entries, ]); foreach ($response->getSuccessful() as $success) { echo "Sent [{$success->getId()}] => MessageId: {$success->getMessageId()}\n"; } foreach ($response->getFailed() as $failure) { echo "Failed [{$failure->getId()}] => {$failure->getCode()}: {$failure->getMessage()}\n"; } } catch (BatchRequestTooLongException $e) { echo "Batch payload too large: " . $e->getMessage() . "\n"; } ``` -------------------------------- ### Subscribe an Endpoint to a Topic Source: https://context7.com/async-aws/sns/llms.txt Subscribes an endpoint (SQS queue, Lambda, HTTP/S URL, email address, SMS number, Firehose stream, or mobile app) to a topic. Supports filter policies to receive only a subset of messages. HTTP/S and email subscriptions require confirmation. ```APIDOC ## `subscribe` — Subscribe an Endpoint to a Topic ### Description Subscribes an endpoint (SQS queue, Lambda, HTTP/S URL, email address, SMS number, Firehose stream, or mobile app) to a topic. HTTP/S and email subscriptions require the endpoint owner to confirm via `ConfirmSubscription`. Supports filter policies to receive only a subset of messages. ### Method POST ### Endpoint / ### Parameters #### Query Parameters - **TopicArn** (string) - Required - The ARN of the topic to subscribe to. - **Protocol** (string) - Required - The protocol to use for the endpoint (e.g., 'sqs', 'lambda', 'email', 'sms'). - **Endpoint** (string) - Required - The endpoint to subscribe (e.g., SQS queue ARN, Lambda function ARN, email address). - **Attributes** (map) - Optional - A map of attributes for the subscription, such as 'RawMessageDelivery' or 'FilterPolicy'. - **ReturnSubscriptionArn** (boolean) - Optional - If true, returns the ARN of the newly created subscription. ### Request Example ```json { "TopicArn": "arn:aws:sns:us-east-1:123456789012:order-notifications", "Protocol": "sqs", "Endpoint": "arn:aws:sqs:us-east-1:123456789012:order-processing-queue", "Attributes": { "RawMessageDelivery": "true" }, "ReturnSubscriptionArn": true } ``` ### Response #### Success Response (200) - **SubscriptionArn** (string) - The ARN of the subscription. May be 'pending confirmation' for email/HTTP subscriptions until confirmed. ``` -------------------------------- ### Publish Up to 10 Messages in a Single Request Source: https://context7.com/async-aws/sns/llms.txt Sends up to 10 messages in one API call. Each entry requires a unique `Id` within the batch. The response separates successful and failed entries — always check `getFailed()` even when the HTTP status is 200. ```APIDOC ## `publishBatch` — Publish Up to 10 Messages in a Single Request ### Description Sends up to 10 messages in one API call. Each entry requires a unique `Id` within the batch. The response separates successful and failed entries — always check `getFailed()` even when the HTTP status is 200. ### Method POST (implied by SDK usage) ### Endpoint Not explicitly defined, SDK method call. ### Parameters #### TopicArn - **TopicArn** (string) - Required - The ARN of the topic to publish to. #### PublishBatchRequestEntries - **PublishBatchRequestEntries** (array) - Required - An array of message entries to publish. - **Id** (string) - Required - An identifier for the message within the batch. - **Message** (string) - Required - The message body. - **Subject** (string) - Optional - The subject of the message. - **MessageAttributes** (array) - Optional - A map of attributes to send with the message. - **MessageGroupId** (string) - Optional - The message group ID for FIFO topics. - **MessageDeduplicationId** (string) - Optional - The message deduplication ID for FIFO topics. ### Request Example ```php $entries = [ new PublishBatchRequestEntry([ 'Id' => 'msg-1', 'Message' => json_encode(['event' => 'user.signup', 'userId' => 101]), 'Subject' => 'User Signup', ]), // ... other entries ]; $response = $sns->publishBatch([ 'TopicArn' => 'arn:aws:sns:us-east-1:123456789012:user-events', 'PublishBatchRequestEntries' => $entries, ]); ``` ### Response #### Success Response - **Successful** (array) - An array of successfully published messages. - **Id** (string) - The identifier of the message. - **MessageId** (string) - The ID of the published message. - **SequenceNumber** (string) - The sequence number for FIFO messages. - **Failed** (array) - An array of failed messages. - **Id** (string) - The identifier of the message. - **Code** (string) - The error code. - **Message** (string) - The error message. #### Response Example ```json { "Successful": [ { "Id": "msg-1", "MessageId": "example-message-id-1", "SequenceNumber": "1234567890" } ], "Failed": [ { "Id": "msg-2", "Code": "InvalidParameter", "Message": "Invalid parameter provided." } ] } ``` ### Error Handling - **BatchRequestTooLongException**: Thrown when the batch payload is too large. ``` -------------------------------- ### Publish a Message to an SNS Topic Source: https://context7.com/async-aws/sns/llms.txt Use this for sending a single message to an SNS topic. It supports simple messages, messages with attributes for filtering, and per-protocol message formatting for different subscribers. ```php use AsyncAws\Sns\SnsClient; use AsyncAws\Sns\ValueObject\MessageAttributeValue; use AsyncAws\Sns\Exception\InvalidParameterException; $sns = new SnsClient(['region' => 'us-east-1']); // --- Simple topic publish --- $response = $sns->publish([ 'TopicArn' => 'arn:aws:sns:us-east-1:123456789012:order-notifications', 'Subject' => 'New Order #42', 'Message' => 'Order #42 has been placed by customer John Doe.', ]); echo "MessageId: " . $response->getMessageId() . "\n"; // --- Publish with message attributes (for subscription filter policies) --- $response = $sns->publish([ 'TopicArn' => 'arn:aws:sns:us-east-1:123456789012:order-notifications', 'Message' => json_encode(['orderId' => 42, 'status' => 'shipped']), 'MessageAttributes' => [ 'eventType' => new MessageAttributeValue([ 'DataType' => 'String', 'StringValue' => 'order.shipped', ]), 'priority' => new MessageAttributeValue([ 'DataType' => 'Number', 'StringValue' => '1', ]), ], ]); echo "MessageId: " . $response->getMessageId() . "\n"; // --- Per-protocol message (different body for email vs SQS) --- $response = $sns->publish([ 'TopicArn' => 'arn:aws:sns:us-east-1:123456789012:order-notifications', 'MessageStructure' => 'json', 'Message' => json_encode([ 'default' => 'Order #42 shipped.', 'email' => "Dear customer,\n\nYour order #42 has been shipped.\n\nRegards,\nShop", 'sqs' => json_encode(['orderId' => 42, 'event' => 'shipped']), ]), ]); // --- Direct SMS to a phone number --- try { $response = $sns->publish([ 'PhoneNumber' => '+12025551234', 'Message' => 'Your verification code is 938271.', ]); echo "SMS MessageId: " . $response->getMessageId() . "\n"; } catch (InvalidParameterException $e) { echo "Invalid parameter: " . $e->getMessage() . "\n"; } // --- FIFO topic publish --- $response = $sns->publish([ 'TopicArn' => 'arn:aws:sns:us-east-1:123456789012:inventory-updates.fifo', 'Message' => json_encode(['sku' => 'PROD-001', 'stock' => 150]), 'MessageGroupId' => 'warehouse-A', 'MessageDeduplicationId' => 'inv-update-' . uniqid(), ]); echo "FIFO SequenceNumber: " . $response->getSequenceNumber() . "\n"; ``` -------------------------------- ### Subscribe Endpoint to SNS Topic Source: https://context7.com/async-aws/sns/llms.txt Subscribes an endpoint to an SNS topic. Supports SQS, Lambda, email, and more. Email and HTTP/S subscriptions require confirmation. Filter policies can be applied for message filtering. ```php use AsyncAws\Sns\SnsClient; use AsyncAws\Sns\Exception\SubscriptionLimitExceededException; $sns = new SnsClient(['region' => 'us-east-1']); $topicArn = 'arn:aws:sns:us-east-1:123456789012:order-notifications'; // --- SQS subscription with raw message delivery --- $sqsResponse = $sns->subscribe([ 'TopicArn' => $topicArn, 'Protocol' => 'sqs', 'Endpoint' => 'arn:aws:sqs:us-east-1:123456789012:order-processing-queue', 'Attributes' => [ 'RawMessageDelivery' => 'true', ], 'ReturnSubscriptionArn' => true, ]); echo "SQS Subscription ARN: " . $sqsResponse->getSubscriptionArn() . "\n"; // --- Lambda subscription with attribute filter policy --- $lambdaResponse = $sns->subscribe([ 'TopicArn' => $topicArn, 'Protocol' => 'lambda', 'Endpoint' => 'arn:aws:lambda:us-east-1:123456789012:function:processShippedOrders', 'Attributes' => [ 'FilterPolicy' => json_encode(['eventType' => ['order.shipped']]), 'FilterPolicyScope' => 'MessageAttributes', ], 'ReturnSubscriptionArn' => true, ]); echo "Lambda Subscription ARN: " . $lambdaResponse->getSubscriptionArn() . "\n"; // --- Email subscription (requires confirmation by recipient) --- try { $emailResponse = $sns->subscribe([ 'TopicArn' => $topicArn, 'Protocol' => 'email', 'Endpoint' => 'ops-team@example.com', 'ReturnSubscriptionArn' => true, ]); // Returns "pending confirmation" until the recipient confirms echo "Email subscription: " . $emailResponse->getSubscriptionArn() . "\n"; } catch (SubscriptionLimitExceededException $e) { echo "Subscription limit reached: " . $e->getMessage() . "\n"; } ``` -------------------------------- ### Publish a Message to a Topic or Endpoint Source: https://context7.com/async-aws/sns/llms.txt Sends a message to an SNS topic, a direct phone number (SMS), or a mobile platform endpoint. Supports per-protocol message formatting via `MessageStructure=json`, typed message attributes, and FIFO deduplication controls. ```APIDOC ## `publish` — Publish a Message to a Topic or Endpoint ### Description Sends a message to an SNS topic, a direct phone number (SMS), or a mobile platform endpoint. Supports per-protocol message formatting via `MessageStructure=json`, typed message attributes, and FIFO deduplication controls. ### Method POST (implied by SDK usage) ### Endpoint Not explicitly defined, SDK method call. ### Parameters #### TopicArn - **TopicArn** (string) - Required - The ARN of the topic to publish to. #### PhoneNumber - **PhoneNumber** (string) - Required - The phone number to send the SMS message to. #### Message - **Message** (string) - Required - The message body. #### Subject - **Subject** (string) - Optional - The subject of the message. #### MessageStructure - **MessageStructure** (string) - Optional - Specifies whether the message is a JSON-formatted string containing per-protocol message bodies. #### MessageAttributes - **MessageAttributes** (array) - Optional - A map of attributes to send with the message. #### MessageGroupId - **MessageGroupId** (string) - Optional - The message group ID for FIFO topics. #### MessageDeduplicationId - **MessageDeduplicationId** (string) - Optional - The message deduplication ID for FIFO topics. ### Request Example ```php $response = $sns->publish([ 'TopicArn' => 'arn:aws:sns:us-east-1:123456789012:order-notifications', 'Subject' => 'New Order #42', 'Message' => 'Order #42 has been placed by customer John Doe.', ]); ``` ### Response #### Success Response - **MessageId** (string) - The ID of the published message. - **SequenceNumber** (string) - The sequence number for FIFO messages. #### Response Example ```json { "MessageId": "example-message-id", "SequenceNumber": "1234567890" } ``` ### Error Handling - **InvalidParameterException**: Thrown when a parameter is invalid. ``` -------------------------------- ### deleteTopic Source: https://context7.com/async-aws/sns/llms.txt Deletes a topic and all its subscriptions. The operation is idempotent — deleting a non-existent topic does not throw an error. ```APIDOC ## `deleteTopic` — Delete an SNS Topic Deletes a topic and all its subscriptions. The operation is idempotent — deleting a non-existent topic does not throw an error. ```php use AsyncAws\Sns\SnsClient; use AsyncAws\Sns\Exception\NotFoundException; $sns = new SnsClient(['region' => 'us-east-1']); try { $result = $sns->deleteTopic([ 'TopicArn' => 'arn:aws:sns:us-east-1:123456789012:order-notifications', ]); // Trigger HTTP resolution (lazy by default) $result->resolve(); echo "Topic deleted successfully.\n"; } catch (NotFoundException $e) { echo "Topic not found: " . $e->getMessage() . "\n"; } ``` ``` -------------------------------- ### Publish Message with Typed Attributes Source: https://context7.com/async-aws/sns/llms.txt Publishes a message to an SNS topic with typed metadata attributes. Supported data types are String, String.Array, Number, and Binary. These attributes are used for subscription filter policies. ```php use AsyncAws\Sns\ValueObject\MessageAttributeValue; use AsyncAws\Sns\SnsClient; $sns = new SnsClient(['region' => 'us-east-1']); $sns->publish([ 'TopicArn' => 'arn:aws:sns:us-east-1:123456789012:events', 'Message' => 'Payment received.', 'MessageAttributes' => [ // String attribute 'transactionType' => new MessageAttributeValue([ 'DataType' => 'String', 'StringValue' => 'payment.received', ]), // Number attribute (stored as String per SNS API contract) 'amount' => new MessageAttributeValue([ 'DataType' => 'Number', 'StringValue' => '99.95', ]), // String.Array attribute (JSON-encoded array) 'tags' => new MessageAttributeValue([ 'DataType' => 'String.Array', 'StringValue' => '["billing","europe","priority"]', ]), // Binary attribute 'checksum' => new MessageAttributeValue([ 'DataType' => 'Binary', 'BinaryValue' => hash('sha256', 'payload', true), // raw binary ]), ], ]); ``` -------------------------------- ### Delete Platform Endpoint Source: https://context7.com/async-aws/sns/llms.txt Deletes a previously created platform application endpoint. This operation is idempotent. Ensure the endpoint is unsubscribed from any topics before deletion. ```php use AsyncAws\Sns\SnsClient; use AsyncAws\Sns\Exception\AuthorizationErrorException; $sns = new SnsClient(['region' => 'us-east-1']); try { $result = $sns->deleteEndpoint([ 'EndpointArn' => 'arn:aws:sns:us-east-1:123456789012:endpoint/GCM/MyAndroidApp/abc123...', ]); $result->resolve(); echo "Endpoint deleted.\n"; } catch (AuthorizationErrorException $e) { echo "Authorization error: " . $e->getMessage() . "\n"; } ``` -------------------------------- ### Delete SNS Topic Source: https://context7.com/async-aws/sns/llms.txt Deletes a topic and all its subscriptions. The operation is idempotent; deleting a non-existent topic does not throw an error. Use resolve() to trigger HTTP resolution for lazy responses. ```php use AsyncAws\Sns\SnsClient; use AsyncAws\Sns\Exception\NotFoundException; $sns = new SnsClient(['region' => 'us-east-1']); try { $result = $sns->deleteTopic([ 'TopicArn' => 'arn:aws:sns:us-east-1:123456789012:order-notifications', ]); // Trigger HTTP resolution (lazy by default) $result->resolve(); echo "Topic deleted successfully.\n"; } catch (NotFoundException $e) { echo "Topic not found: " . $e->getMessage() . "\n"; } ``` -------------------------------- ### deleteEndpoint Source: https://context7.com/async-aws/sns/llms.txt Deletes a platform application endpoint. This operation is idempotent. ```APIDOC ## `deleteEndpoint` — Remove a Mobile Device Endpoint Deletes a platform application endpoint. The operation is idempotent. If the endpoint is also subscribed to a topic, unsubscribe it separately first. ### Method POST ### Endpoint / ### Parameters #### Query Parameters - **Action** (string) - Required - `DeleteEndpoint` - **Version** (string) - Required - `2010-03-31` #### Request Body - **EndpointArn** (string) - Required - The ARN of the endpoint to delete. ### Request Example ```json { "EndpointArn": "arn:aws:sns:us-east-1:123456789012:endpoint/GCM/MyAndroidApp/abc123..." } ``` ### Response #### Success Response (200) An empty response indicates success. #### Response Example (No specific example provided, success is indicated by the absence of an error.) ``` -------------------------------- ### Unsubscribe from a Topic Source: https://context7.com/async-aws/sns/llms.txt Removes a subscription by its ARN. Only the subscription owner or topic owner can call this operation if the subscription requires authentication for deletion. ```APIDOC ## `unsubscribe` — Remove a Subscription ### Description Removes a subscription by its ARN. If the subscription requires authentication for deletion, only the subscription owner or topic owner can call this operation. ### Method POST ### Endpoint / ### Parameters #### Query Parameters - **SubscriptionArn** (string) - Required - The ARN of the subscription to remove. ### Request Example ```json { "SubscriptionArn": "arn:aws:sns:us-east-1:123456789012:order-notifications:abc12345-6789-def0-1234-56789abcdef0" } ``` ### Response #### Success Response (200) - **Result** (boolean) - Indicates if the unsubscribe operation was successful. ``` -------------------------------- ### Unsubscribe from SNS Topic Source: https://context7.com/async-aws/sns/llms.txt Removes a subscription from an SNS topic using its ARN. Requires authentication if the subscription is protected. Handles cases where the subscription is not found. ```php use AsyncAws\Sns\SnsClient; use AsyncAws\Sns\Exception\NotFoundException; $sns = new SnsClient(['region' => 'us-east-1']); try { $result = $sns->unsubscribe([ 'SubscriptionArn' => 'arn:aws:sns:us-east-1:123456789012:order-notifications:abc12345-6789-def0-1234-56789abcdef0', ]); $result->resolve(); echo "Unsubscribed successfully.\n"; } catch (NotFoundException $e) { echo "Subscription not found: " . $e->getMessage() . "\n"; } ``` -------------------------------- ### MessageAttributeValue Source: https://context7.com/async-aws/sns/llms.txt Represents a typed message attribute for use with subscription filter policies. Supports String, String.Array, Number, and Binary data types. ```APIDOC ## `MessageAttributeValue` — Typed Message Attribute Attaches metadata to published messages for use by subscription filter policies. Supported `DataType` values are `String`, `String.Array`, `Number`, and `Binary`. ### Usage This is a value object used within the `publish` operation's `MessageAttributes` parameter. ### Parameters - **DataType** (string) - Required - The type of the attribute. Supported values: `String`, `String.Array`, `Number`, `Binary`. - **StringValue** (string) - Required if `DataType` is `String`, `String.Array`, or `Number`. The string representation of the attribute value. - **BinaryValue** (string) - Required if `DataType` is `Binary`. The base64-encoded binary value of the attribute. ### Example Usage in `publish` operation: ```php use AsyncAws\Sns\ValueObject\MessageAttributeValue; // ... within the publish call ... 'MessageAttributes' => [ 'transactionType' => new MessageAttributeValue([ 'DataType' => 'String', 'StringValue' => 'payment.received', ]), 'amount' => new MessageAttributeValue([ 'DataType' => 'Number', 'StringValue' => '99.95', ]), 'tags' => new MessageAttributeValue([ 'DataType' => 'String.Array', 'StringValue' => '["billing","europe","priority"]', ]), 'checksum' => new MessageAttributeValue([ 'DataType' => 'Binary', 'BinaryValue' => hash('sha256', 'payload', true), // raw binary ]), ] // ... ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.