LinuxCommandLibrary

aws-sns

Manage and interact with Amazon SNS

TLDR

List all objects of a specific type

$ aws sns list-[origination-numbers|phone-numbers-opted-out|platform-applications|sms-sandbox-phone-numbers|subscriptions|topics]
copy

Create a topic with a specific name and show its Amazon Resource Name (ARN)
$ aws sns create-topic --name [name]
copy

Subscribe an email address to the topic with a specific ARN and show the subscription ARN
$ aws sns subscribe --topic-arn [topic_ARN] --protocol email --notification-endpoint [email]
copy

Publish a message to a specific topic or phone number and show the message ID
$ aws sns publish [--topic-arn "arn:aws:sns:us-west-2:123456789012:topic-name"||--phone-number +1-555-555-0100] --message file://[path/to/file]
copy

Delete the subscription with a specific ARN from its topic
$ aws sns unsubscribe --subscription-arn [subscription_ARN]
copy

Create a platform endpoint
$ aws sns create-platform-endpoint --platform-application-arn [platform_application_ARN] --token [token]
copy

Add a statement to a topic's access control policy
$ aws sns add-permission --topic-arn [topic_ARN] --label [topic_label] --aws-account-id [account_id] --action-name [AddPermission|CreatePlatformApplication|DeleteEndpoint|GetDataProtectionPolicy|GetEndpointAttributes|Subscribe|...]
copy

Add a tag to the topic with a specific ARN
$ aws sns tag-resource --resource-arn [topic_ARN] --tags [Key=tag1_key Key=tag2_key,Value=tag2_value ...]
copy

SYNOPSIS

aws sns subcommand [options]
Examples:
aws sns publish --topic-arn string --message string
aws sns create-topic --name string
aws sns subscribe --topic-arn string --protocol string --notification-endpoint string

PARAMETERS

--region string
    Specifies the AWS region to send the request to. This is a global AWS CLI option.

--output string
    The formatting style for command output (e.g., json, text, table). This is a global AWS CLI option.

--profile string
    Uses a specific profile from your credential file. This is a global AWS CLI option.

--topic-arn string
    A common parameter for many SNS commands, specifying the Amazon Resource Name (ARN) of the SNS topic.

--message string
    Used specifically with the publish subcommand to specify the message body to send.

--name string
    Used with subcommands like create-topic or get-topic-attributes to specify the name of the topic.

--protocol string
    Used with the subscribe subcommand to define the delivery protocol (e.g., http, email, sms, sqs, lambda).

--notification-endpoint string
    Used with the subscribe subcommand to specify the endpoint that receives notifications.

DESCRIPTION

The term "aws-sns" does not refer to a standalone Linux command. Instead, it typically refers to the AWS Command Line Interface (AWS CLI) service namespace used to interact with AWS Simple Notification Service (SNS). The AWS CLI provides a unified tool to manage your AWS services from the command line. When you use aws sns, you are leveraging the AWS CLI to programmatically access and manage SNS resources. This includes publishing messages to topics, creating and managing SNS topics, subscribing endpoints (like email, SMS, SQS, Lambda) to topics, and configuring topic attributes like access policies. It's an essential tool for automating tasks, scripting, and integrating SNS with other systems without needing the AWS Management Console.

CAVEATS

Using aws sns requires the AWS CLI to be installed and configured with valid AWS credentials and a default region. Users must possess the necessary IAM permissions to perform SNS operations (e.g., sns:Publish, sns:Subscribe, sns:CreateTopic), otherwise, Access Denied errors will occur. AWS SNS incurs costs based on the number of messages published, deliveries, and data transfer; users should be aware of pricing. Be mindful of AWS service quotas and rate limits to avoid throttling errors. Output from commands is typically in JSON format, requiring tools like jq for efficient parsing in scripts.

COMMON SNS OPERATIONS

The aws sns command suite facilitates a wide range of operations, including:
publishing messages to topics (e.g., publish),
managing subscriptions (e.g., subscribe, unsubscribe, list-subscriptions-by-topic),
creating and deleting topics (e.g., create-topic, delete-topic), and
configuring topic attributes (e.g., set-topic-attributes, get-topic-attributes).

INTEGRATION WITH AWS SERVICES

SNS often integrates with other AWS services. For instance, messages can be delivered to AWS Lambda functions, Amazon SQS queues, or directly to users via SMS and email, all configurable via aws sns commands. This makes it a central component in event-driven architectures.

HISTORY

The AWS Command Line Interface (AWS CLI) was initially released in 2013, providing a consistent and unified tool for managing AWS services, including Simple Notification Service (SNS). While SNS launched in 2010, the aws sns interface has continuously evolved with new SNS features and improvements, reflecting the service's expanding capabilities and integration options. Its development focuses on enabling robust automation and programmatic control over notification workflows.

SEE ALSO

aws(1), aws s3(1), aws lambda(1), jq(1), curl(1)

Copied to clipboard