AWS SDK for JavaScript SNS Client for Node.js, Browser and React Native
npx @tessl/cli install tessl/npm-aws-sdk--client-sns@3.879.0AWS SDK for JavaScript SNS Client provides a comprehensive TypeScript library for Amazon Simple Notification Service (SNS). It enables developers to build distributed web applications with real-time push notification capabilities across multiple delivery protocols including email, SMS, HTTP/HTTPS endpoints, and mobile push notifications.
npm install @aws-sdk/client-snsimport { SNSClient, CreateTopicCommand, PublishCommand } from "@aws-sdk/client-sns";For aggregated client with all methods:
import { SNS } from "@aws-sdk/client-sns";CommonJS:
const { SNSClient, CreateTopicCommand, PublishCommand } = require("@aws-sdk/client-sns");import { SNSClient, CreateTopicCommand, PublishCommand } from "@aws-sdk/client-sns";
// Create client
const client = new SNSClient({ region: "us-east-1" });
// Create a topic
const createTopicResult = await client.send(new CreateTopicCommand({
Name: "MyTopic"
}));
// Publish a message
const publishResult = await client.send(new PublishCommand({
TopicArn: createTopicResult.TopicArn,
Message: "Hello from SNS!",
Subject: "Test Message"
}));The AWS SNS client follows a command-based architecture with these key components:
Core client setup and configuration options for AWS SNS service access.
class SNSClient {
constructor(configuration: SNSClientConfig);
send<InputType, OutputType>(
command: Command<InputType, OutputType, SNSClientResolvedConfig>
): Promise<OutputType>;
destroy(): void;
}
interface SNSClientConfig {
region?: string | Provider<string>;
credentials?: AwsCredentialIdentityProvider;
maxAttempts?: number | Provider<number>;
retryMode?: string | Provider<string>;
requestHandler?: RequestHandler<any, any>;
logger?: Logger;
useDualstackEndpoint?: boolean | Provider<boolean>;
useFipsEndpoint?: boolean | Provider<boolean>;
}Create, delete, and manage SNS topics with comprehensive attribute control and listing capabilities.
class CreateTopicCommand {
constructor(input: CreateTopicInput);
}
interface CreateTopicInput {
Name: string | undefined;
Attributes?: Record<string, string> | undefined;
Tags?: Tag[] | undefined;
DataProtectionPolicy?: string | undefined;
}
interface CreateTopicResponse {
TopicArn?: string;
}Publish messages to topics and endpoints with support for message attributes, batch operations, and various delivery protocols.
class PublishCommand {
constructor(input: PublishInput);
}
interface PublishInput {
TopicArn?: string | undefined;
TargetArn?: string | undefined;
PhoneNumber?: string | undefined;
Message: string | undefined;
Subject?: string | undefined;
MessageStructure?: string | undefined;
MessageAttributes?: Record<string, MessageAttributeValue> | undefined;
MessageGroupId?: string | undefined;
MessageDeduplicationId?: string | undefined;
}
interface PublishResponse {
MessageId?: string;
SequenceNumber?: string;
}Subscribe endpoints to topics, manage subscription attributes, and handle subscription confirmation workflows.
class SubscribeCommand {
constructor(input: SubscribeInput);
}
interface SubscribeInput {
TopicArn: string;
Protocol: string;
Endpoint?: string;
Attributes?: SubscriptionAttributesMap;
ReturnSubscriptionArn?: boolean;
}
interface SubscribeResponse {
SubscriptionArn?: string;
}Manage mobile push notification platform applications and device endpoints for iOS, Android, and other platforms.
class CreatePlatformApplicationCommand {
constructor(input: CreatePlatformApplicationInput);
}
interface CreatePlatformApplicationInput {
Name: string;
Platform: string;
Attributes: PlatformApplicationAttributesMap;
}
interface CreatePlatformApplicationResponse {
PlatformApplicationArn?: string;
}Platform Applications and Endpoints
Comprehensive SMS functionality including attributes configuration, phone number opt-out management, and sandbox environment support.
class SetSMSAttributesCommand {
constructor(input: SetSMSAttributesInput);
}
interface SetSMSAttributesInput {
attributes: SMSAttributesMap;
}
interface SMSAttributesMap {
[key: string]: string;
}Add and remove permissions for SNS topics to control access across AWS accounts and services.
class AddPermissionCommand {
constructor(input: AddPermissionInput);
}
interface AddPermissionInput {
TopicArn: string;
Label: string;
AWSAccountId: string[];
ActionName: string[];
}Tag SNS resources for organization, cost allocation, and access control with comprehensive tag management capabilities.
class TagResourceCommand {
constructor(input: TagResourceRequest);
}
interface TagResourceRequest {
ResourceArn: string;
Tags: Tag[];
}
interface Tag {
Key: string;
Value: string;
}Configure data protection policies for SNS topics to control data handling and privacy compliance.
class PutDataProtectionPolicyCommand {
constructor(input: PutDataProtectionPolicyInput);
}
interface PutDataProtectionPolicyInput {
ResourceArn: string;
DataProtectionPolicy: string;
}Paginated listing operations for topics, subscriptions, platform applications, and other SNS resources.
function paginateListTopics(
config: SNSPaginationConfiguration,
input: ListTopicsInput
): Paginator<ListTopicsCommandOutput>;
interface SNSPaginationConfiguration extends PaginationConfiguration {
client: SNSClient;
}List Operations and Pagination
interface Topic {
TopicArn?: string;
}
interface Subscription {
SubscriptionArn?: string;
Owner?: string;
Protocol?: string;
Endpoint?: string;
TopicArn?: string;
}
interface Endpoint {
EndpointArn?: string;
Attributes?: EndpointAttributesMap;
}
interface MessageAttributeValue {
DataType: string;
StringValue?: string;
BinaryValue?: Uint8Array;
StringListValues?: string[];
BinaryListValues?: Uint8Array[];
}
interface PlatformApplication {
PlatformApplicationArn?: string;
Attributes?: PlatformApplicationAttributesMap;
}The SNS client provides comprehensive error handling with strongly-typed exceptions for different error scenarios:
class SNSServiceException extends Error {
name: string;
$fault: 'client' | 'server';
$metadata: ResponseMetadata;
}
class AuthorizationErrorException extends SNSServiceException {
name: 'AuthorizationErrorException';
$fault: 'client';
}
class InvalidParameterException extends SNSServiceException {
name: 'InvalidParameterException';
$fault: 'client';
}
class InternalErrorException extends SNSServiceException {
name: 'InternalErrorException';
$fault: 'server';
}
class NotFoundException extends SNSServiceException {
name: 'NotFoundException';
$fault: 'client';
}
class ThrottledException extends SNSServiceException {
name: 'ThrottledException';
$fault: 'server';
}enum LanguageCodeString {
de_DE = 'de-DE',
en_GB = 'en-GB',
en_US = 'en-US',
es_419 = 'es-419',
es_ES = 'es-ES',
fr_CA = 'fr-CA',
fr_FR = 'fr-FR',
it_IT = 'it-IT',
jp_JP = 'ja-JP',
kr_KR = 'kr-KR',
pt_BR = 'pt-BR',
zh_CN = 'zh-CN',
zh_TW = 'zh-TW'
}
enum NumberCapability {
MMS = 'MMS',
SMS = 'SMS',
VOICE = 'VOICE'
}
enum RouteType {
Premium = 'Premium',
Promotional = 'Promotional',
Transactional = 'Transactional'
}
enum SMSSandboxPhoneNumberVerificationStatus {
Pending = 'Pending',
Verified = 'Verified'
}