- 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.
SubscribeCommand
Subscribes an endpoint to an Amazon SNS topic. If the endpoint type is HTTP/S or email, or if the endpoint and the topic are not in the same Amazon Web Services account, the endpoint owner must run the ConfirmSubscription
action to confirm the subscription.
You call the ConfirmSubscription
action with the token from the subscription response. Confirmation tokens are valid for two days.
This action is throttled at 100 transactions per second (TPS).
Example Syntax
Use a bare-bones client and the command you need to make an API call.
import { SNSClient, SubscribeCommand } from "@aws-sdk/client-sns"; // ES Modules import
// const { SNSClient, SubscribeCommand } = require("@aws-sdk/client-sns"); // CommonJS import
const client = new SNSClient(config);
const input = { // SubscribeInput
TopicArn: "STRING_VALUE", // required
Protocol: "STRING_VALUE", // required
Endpoint: "STRING_VALUE",
Attributes: { // SubscriptionAttributesMap
"<keys>": "STRING_VALUE",
},
ReturnSubscriptionArn: true || false,
};
const command = new SubscribeCommand(input);
const response = await client.send(command);
// { // SubscribeResponse
// SubscriptionArn: "STRING_VALUE",
// };
SubscribeCommand Input
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
Protocol Required | string | undefined | The protocol that you want to use. Supported protocols include:
|
TopicArn Required | string | undefined | The ARN of the topic you want to subscribe to. |
Attributes | Record<string, string> | undefined | A map of attributes with their corresponding values. The following lists the names, descriptions, and values of the special request parameters that the
The following attribute applies only to Amazon Data Firehose delivery stream subscriptions:
The following attributes apply only to FIFO topics :
|
Endpoint | string | undefined | The endpoint that you want to receive notifications. Endpoints vary by protocol:
|
ReturnSubscriptionArn | boolean | undefined | Sets whether the response from the If you set this parameter to The default value is |
SubscribeCommand Output
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
$metadata Required | ResponseMetadata | Metadata pertaining to this request. |
SubscriptionArn | string | undefined | The ARN of the subscription if it is confirmed, or the string "pending confirmation" if the subscription requires confirmation. However, if the API request parameter |
Throws
Name | Fault | Details |
---|
Name | Fault | Details |
---|---|---|
AuthorizationErrorException | client | Indicates that the user has been denied access to the requested resource. |
FilterPolicyLimitExceededException | client | Indicates that the number of filter polices in your Amazon Web Services account exceeds the limit. To add more filter polices, submit an Amazon SNS Limit Increase case in the Amazon Web Services Support Center. |
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. |
NotFoundException | client | Indicates that the requested resource does not exist. |
ReplayLimitExceededException | client | Indicates that the request parameter has exceeded the maximum number of concurrent message replays. |
SubscriptionLimitExceededException | client | Indicates that the customer already owns the maximum allowed number of subscriptions. |
SNSServiceException | Base exception class for all service exceptions from SNS service. |