The SNS client configuration provides comprehensive options for customizing AWS SDK behavior including authentication, networking, retry logic, and environmental settings.
Creates a new SNS client instance with specified configuration options.
/**
* Creates a new SNS client instance
* @param configuration - Client configuration options
*/
class SNSClient {
constructor(configuration: SNSClientConfig);
send<InputType, OutputType>(
command: Command<InputType, OutputType, SNSClientResolvedConfig>
): Promise<OutputType>;
destroy(): void;
}
interface SNSClientConfig {
/** AWS region for API requests */
region?: string | Provider<string>;
/** AWS credentials provider for authentication */
credentials?: AwsCredentialIdentityProvider;
/** Maximum number of retry attempts for failed requests */
maxAttempts?: number | Provider<number>;
/** Retry mode algorithm (standard, adaptive) */
retryMode?: string | Provider<string>;
/** Custom HTTP request handler */
requestHandler?: RequestHandler<any, any>;
/** Logger for debug/info/warn/error messages */
logger?: Logger;
/** Enable IPv6/IPv4 dual-stack endpoints */
useDualstackEndpoint?: boolean | Provider<boolean>;
/** Enable FIPS compliant endpoints */
useFipsEndpoint?: boolean | Provider<boolean>;
/** Custom endpoint URL override */
endpoint?: string | Provider<string> | Endpoint | Provider<Endpoint>;
/** AWS configuration profile name */
profile?: string;
/** SDK defaults mode for configuration */
defaultsMode?: DefaultsMode | Provider<DefaultsMode>;
/** Runtime extensions for middleware customization */
extensions?: RuntimeExtension[];
/** Disable dynamic endpoint changes based on hostPrefix trait */
disableHostPrefix?: boolean;
}Basic Configuration:
import { SNSClient } from "@aws-sdk/client-sns";
// Minimal configuration
const client = new SNSClient({ region: "us-east-1" });
// With credentials
const client = new SNSClient({
region: "us-east-1",
credentials: {
accessKeyId: "your-access-key",
secretAccessKey: "your-secret-key"
}
});Advanced Configuration:
import { SNSClient } from "@aws-sdk/client-sns";
const client = new SNSClient({
region: "us-east-1",
maxAttempts: 5,
retryMode: "adaptive",
useDualstackEndpoint: true,
useFipsEndpoint: true,
logger: console,
defaultsMode: "in-region"
});Alternative client that provides all SNS operations as direct methods instead of using command pattern.
/**
* Aggregated client with all SNS operations as methods
*/
class SNS {
constructor(configuration: SNSClientConfig);
/** Create a new topic */
createTopic(args: CreateTopicCommandInput): Promise<CreateTopicCommandOutput>;
/** Delete a topic */
deleteTopic(args: DeleteTopicCommandInput): Promise<DeleteTopicCommandOutput>;
/** Publish a message */
publish(args: PublishCommandInput): Promise<PublishCommandOutput>;
/** Subscribe to a topic */
subscribe(args: SubscribeCommandInput): Promise<SubscribeCommandOutput>;
/** List all topics */
listTopics(args?: ListTopicsCommandInput): Promise<ListTopicsCommandOutput>;
// ... all other SNS operations as methods
}Usage Example:
import { SNS } from "@aws-sdk/client-sns";
const sns = new SNS({ region: "us-east-1" });
// Direct method calls (no commands needed)
const topic = await sns.createTopic({ Name: "MyTopic" });
const result = await sns.publish({
TopicArn: topic.TopicArn,
Message: "Hello World"
});Core configuration interfaces and types used throughout the client.
interface SNSClientResolvedConfig {
region: Provider<string>;
credentials: AwsCredentialIdentityProvider;
maxAttempts: Provider<number>;
retryMode: Provider<string>;
requestHandler: RequestHandler<any, any>;
logger: Logger;
useDualstackEndpoint: Provider<boolean>;
useFipsEndpoint: Provider<boolean>;
endpoint: Provider<Endpoint>;
defaultsMode: Provider<DefaultsMode>;
extensions: RuntimeExtension[];
disableHostPrefix: boolean;
}
type Provider<T> = T | (() => Promise<T>) | (() => T);
interface DefaultsMode {
mode: 'standard' | 'in-region' | 'cross-region' | 'mobile' | 'auto' | 'legacy';
}
interface RuntimeExtension {
configure(extensionConfiguration: ExtensionConfiguration): void;
}Methods for managing client lifecycle and resources.
/**
* Destroys the client and cleans up underlying resources
* Call this when you're done using the client to prevent memory leaks
*/
destroy(): void;Usage Example:
const client = new SNSClient({ region: "us-east-1" });
try {
// Use client for operations
await client.send(new CreateTopicCommand({ Name: "MyTopic" }));
} finally {
// Clean up resources
client.destroy();
}The client automatically adapts configuration based on the runtime environment.
Node.js Default Configuration:
Browser Default Configuration:
React Native Default Configuration:
Union types encompassing all possible command inputs and outputs.
type ServiceInputTypes =
| AddPermissionCommandInput
| CheckIfPhoneNumberIsOptedOutCommandInput
| ConfirmSubscriptionCommandInput
| CreatePlatformApplicationCommandInput
| CreatePlatformEndpointCommandInput
| CreateSMSSandboxPhoneNumberCommandInput
| CreateTopicCommandInput
| DeleteEndpointCommandInput
| DeletePlatformApplicationCommandInput
| DeleteSMSSandboxPhoneNumberCommandInput
| DeleteTopicCommandInput
| GetDataProtectionPolicyCommandInput
| GetEndpointAttributesCommandInput
| GetPlatformApplicationAttributesCommandInput
| GetSMSAttributesCommandInput
| GetSMSSandboxAccountStatusCommandInput
| GetSubscriptionAttributesCommandInput
| GetTopicAttributesCommandInput
| ListEndpointsByPlatformApplicationCommandInput
| ListOriginationNumbersCommandInput
| ListPhoneNumbersOptedOutCommandInput
| ListPlatformApplicationsCommandInput
| ListSMSSandboxPhoneNumbersCommandInput
| ListSubscriptionsByTopicCommandInput
| ListSubscriptionsCommandInput
| ListTagsForResourceCommandInput
| ListTopicsCommandInput
| OptInPhoneNumberCommandInput
| PublishBatchCommandInput
| PublishCommandInput
| PutDataProtectionPolicyCommandInput
| RemovePermissionCommandInput
| SetEndpointAttributesCommandInput
| SetPlatformApplicationAttributesCommandInput
| SetSMSAttributesCommandInput
| SetSubscriptionAttributesCommandInput
| SetTopicAttributesCommandInput
| SubscribeCommandInput
| TagResourceCommandInput
| UnsubscribeCommandInput
| UntagResourceCommandInput
| VerifySMSSandboxPhoneNumberCommandInput;
type ServiceOutputTypes =
| AddPermissionCommandOutput
| CheckIfPhoneNumberIsOptedOutCommandOutput
| ConfirmSubscriptionCommandOutput
| CreatePlatformApplicationCommandOutput
| CreatePlatformEndpointCommandOutput
| CreateSMSSandboxPhoneNumberCommandOutput
| CreateTopicCommandOutput
| DeleteEndpointCommandOutput
| DeletePlatformApplicationCommandOutput
| DeleteSMSSandboxPhoneNumberCommandOutput
| DeleteTopicCommandOutput
| GetDataProtectionPolicyCommandOutput
| GetEndpointAttributesCommandOutput
| GetPlatformApplicationAttributesCommandOutput
| GetSMSAttributesCommandOutput
| GetSMSSandboxAccountStatusCommandOutput
| GetSubscriptionAttributesCommandOutput
| GetTopicAttributesCommandOutput
| ListEndpointsByPlatformApplicationCommandOutput
| ListOriginationNumbersCommandOutput
| ListPhoneNumbersOptedOutCommandOutput
| ListPlatformApplicationsCommandOutput
| ListSMSSandboxPhoneNumbersCommandOutput
| ListSubscriptionsByTopicCommandOutput
| ListSubscriptionsCommandOutput
| ListTagsForResourceCommandOutput
| ListTopicsCommandOutput
| OptInPhoneNumberCommandOutput
| PublishBatchCommandOutput
| PublishCommandOutput
| PutDataProtectionPolicyCommandOutput
| RemovePermissionCommandOutput
| SetEndpointAttributesCommandOutput
| SetPlatformApplicationAttributesCommandOutput
| SetSMSAttributesCommandOutput
| SetSubscriptionAttributesCommandOutput
| SetTopicAttributesCommandOutput
| SubscribeCommandOutput
| TagResourceCommandOutput
| UnsubscribeCommandOutput
| UntagResourceCommandOutput
| VerifySMSSandboxPhoneNumberCommandOutput;