- Navigation GuideYou are on a Command (operation) page with structural examples. Use the navigation breadcrumb if you would like to return to the Client landing page.
CreateTopicCommand
Creates a topic to which notifications can be published. Users can create at most 100,000 standard topics (at most 1,000 FIFO topics). For more information, see Creating an Amazon SNS topic in the Amazon SNS Developer Guide. This action is idempotent, so if the requester already owns a topic with the specified name, that topic's ARN is returned without creating a new topic.
Example Syntax
Use a bare-bones client and the command you need to make an API call.
import { SNSClient, CreateTopicCommand } from "@aws-sdk/client-sns"; // ES Modules import
// const { SNSClient, CreateTopicCommand } = require("@aws-sdk/client-sns"); // CommonJS import
const client = new SNSClient(config);
const input = { // CreateTopicInput
Name: "STRING_VALUE", // required
Attributes: { // TopicAttributesMap
"<keys>": "STRING_VALUE",
},
Tags: [ // TagList
{ // Tag
Key: "STRING_VALUE", // required
Value: "STRING_VALUE", // required
},
],
DataProtectionPolicy: "STRING_VALUE",
};
const command = new CreateTopicCommand(input);
const response = await client.send(command);
// { // CreateTopicResponse
// TopicArn: "STRING_VALUE",
// };
CreateTopicCommand Input
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
Name Required | string | undefined | The name of the topic you want to create. Constraints: Topic names must be made up of only uppercase and lowercase ASCII letters, numbers, underscores, and hyphens, and must be between 1 and 256 characters long. For a FIFO (first-in-first-out) topic, the name must end with the |
Attributes | Record<string, string> | undefined | A map of attributes with their corresponding values. The following lists names, descriptions, and values of the special request parameters that the
The following attribute applies only to server-side encryption : The following attributes apply only to FIFO topics :
|
DataProtectionPolicy | string | undefined | The body of the policy document you want to use for this topic. You can only add one policy per topic. The policy must be in JSON string format. Length Constraints: Maximum length of 30,720. |
Tags | Tag[] | undefined | The list of tags to add to a new topic. To be able to tag a topic on creation, you must have the |
CreateTopicCommand Output
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
$metadata Required | ResponseMetadata | Metadata pertaining to this request. |
TopicArn | string | undefined | The Amazon Resource Name (ARN) assigned to the created topic. |
Throws
Name | Fault | Details |
---|
Name | Fault | Details |
---|---|---|
AuthorizationErrorException | client | Indicates that the user has been denied access to the requested resource. |
ConcurrentAccessException | client | Can't perform multiple operations on a tag simultaneously. Perform the operations sequentially. |
InternalErrorException | server | Indicates an internal service error. |
InvalidParameterException | client | Indicates that a request parameter does not comply with the associated constraints. |
InvalidSecurityException | client | The credential signature isn't valid. You must use an HTTPS endpoint and sign your request using Signature Version 4. |
StaleTagException | client | A tag has been added to a resource with the same ARN as a deleted resource. Wait a short while and then retry the operation. |
TagLimitExceededException | client | Can't add more than 50 tags to a topic. |
TagPolicyException | client | The request doesn't comply with the IAM tag policy. Correct your request and then retry it. |
TopicLimitExceededException | client | Indicates that the customer already owns the maximum allowed number of topics. |
SNSServiceException | Base exception class for all service exceptions from SNS service. |