// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import { fileURLToPath } from "node:url"; // snippet-start:[javascript.v3.sns.hello] import { SNSClient, paginateListTopics } from "@aws-sdk/client-sns"; export const helloSns = async () => { // The configuration object (`{}`) is required. If the region and credentials // are omitted, the SDK uses your local configuration if it exists. const client = new SNSClient({}); // You can also use `ListTopicsCommand`, but to use that command you must // handle the pagination yourself. You can do that by sending the `ListTopicsCommand` // with the `NextToken` parameter from the previous request. const paginatedTopics = paginateListTopics({ client }, {}); const topics = []; for await (const page of paginatedTopics) { if (page.Topics?.length) { topics.push(...page.Topics); } } const suffix = topics.length === 1 ? "" : "s"; console.log( `Hello, Amazon SNS! You have ${topics.length} topic${suffix} in your account.`, ); console.log(topics.map((t) => ` * ${t.TopicArn}`).join("\n")); }; // snippet-end:[javascript.v3.sns.hello] // Invoke main function if this file was run directly. if (process.argv[1] === fileURLToPath(import.meta.url)) { helloSns(); }