Jump to Content

Class PublishCommandProtected

Sends a message to an Amazon SNS topic, a text message (SMS message) directly to a phone number, or a message to a mobile platform endpoint (when you specify the TargetArn).

If you send a message to a topic, Amazon SNS delivers the message to each endpoint that is subscribed to the topic. The format of the message depends on the notification protocol for each subscribed endpoint.

When a messageId is returned, the message is saved and Amazon SNS immediately delivers it to subscribers.

To use the Publish action for publishing a message to a mobile endpoint, such as an app on a Kindle device or mobile phone, you must specify the EndpointArn for the TargetArn parameter. The EndpointArn is returned when making a call with the CreatePlatformEndpoint action.

For more information about formatting messages, see Send Custom Platform-Specific Payloads in Messages to Mobile Devices.

You can publish messages only to topics and endpoints in the same Amazon Web Services Region.

Example

Use a bare-bones client and the command you need to make an API call.

import { SNSClient, PublishCommand } from "@aws-sdk/client-sns"; // ES Modules import
// const { SNSClient, PublishCommand } = require("@aws-sdk/client-sns"); // CommonJS import
const client = new SNSClient(config);
const command = new PublishCommand(input);
const response = await client.send(command);

See

Throws

AuthorizationErrorException (client fault)

Indicates that the user has been denied access to the requested resource.

Throws

EndpointDisabledException (client fault)

Exception error indicating endpoint disabled.

Throws

InternalErrorException (server fault)

Indicates an internal service error.

Throws

InvalidParameterException (client fault)

Indicates that a request parameter does not comply with the associated constraints.

Throws

InvalidParameterValueException (client fault)

Indicates that a request parameter does not comply with the associated constraints.

Throws

InvalidSecurityException (client fault)

The credential signature isn't valid. You must use an HTTPS endpoint and sign your request using Signature Version 4.

Throws

KMSAccessDeniedException (client fault)

The ciphertext references a key that doesn't exist or that you don't have access to.

Throws

KMSDisabledException (client fault)

The request was rejected because the specified customer master key (CMK) isn't enabled.

Throws

KMSInvalidStateException (client fault)

The request was rejected because the state of the specified resource isn't valid for this request. For more information, see How Key State Affects Use of a Customer Master Key in the Key Management Service Developer Guide.

Throws

KMSNotFoundException (client fault)

The request was rejected because the specified entity or resource can't be found.

Throws

KMSOptInRequired (client fault)

The Amazon Web Services access key ID needs a subscription for the service.

Throws

KMSThrottlingException (client fault)

The request was denied due to request throttling. For more information about throttling, see Limits in the Key Management Service Developer Guide.

Throws

NotFoundException (client fault)

Indicates that the requested resource does not exist.

Throws

PlatformApplicationDisabledException (client fault)

Exception error indicating platform application disabled.

Throws

ValidationException (client fault)

Indicates that a parameter in the request is invalid.

Hierarchy

Constructors

Properties

middlewareStack: MiddlewareStack<PublishCommandInput, PublishCommandOutput>

Methods