AWS Amazon SNS Topic

This page shows how to write Terraform and CloudFormation for Amazon SNS Topic and write them securely.

aws_sns_topic (Terraform)

The Topic in Amazon SNS can be configured in Terraform with the resource name aws_sns_topic. The following sections describe 4 examples of how to use the resource and its parameters.

Example Usage from GitHub

sns.tf#L1
resource "aws_sns_topic" "us_east_1" {
  count = contains(var.enabled_regions, "us-east-1") ? 1 : 0

  name_prefix       = "aws-config-notify-us_east_1"
  display_name      = "AWS Config US-EAST-1"
  kms_master_key_id = "alias/aws/sns"
sns.tf#L1
resource "aws_sns_topic" "redshift-diskspace-cloudwatch-alarms-topic-sns" {
  name = "redshift-diskspace-cloudwatch-alarms-topic-sns"
}

resource "aws_sns_topic" "redshift-healthstatus-cloudwatch-alarms-topic-sns" {
  name = "redshift-healthstatus-cloudwatch-alarms-topic-sns"
main.tf#L10
resource "aws_sns_topic" "player_progress_topic" {
  name = "player-progress-topic"
  tags = local.tags
}

resource "aws_sns_topic" "leader_board_topic" {
sns_restricted_principal.tf#L11
resource "aws_sns_topic" "test_a" {
  name = "test_a"
}

# INVALID: sns topic policy extends permissions to all principals
resource "aws_sns_topic_policy" "invalid_policy_a" {

Review your Terraform file for AWS best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

Provides an SNS topic resource

AWS::SNS::Topic (CloudFormation)

The Topic in SNS can be configured in CloudFormation with the resource name AWS::SNS::Topic. The following sections describe 10 examples of how to use the resource and its parameters.

Example Usage from GitHub

serverless.yml#L56
      Type: AWS::SNS::Topic
      Properties:
        TopicName: hca-text-members
    MenTopic:
      Type: AWS::SNS::Topic
      Properties:
02-SNS-Monitoring.yml#L35
    Type: AWS::SNS::Topic
    Properties:
      DisplayName: DISK_ALERT
      TopicName: !Join
            - '-'
            - - !Ref Environment
02-SNS-Monitoring.yml#L35
    Type: AWS::SNS::Topic
    Properties:
      DisplayName: DISK_ALERT
      TopicName: !Join
            - '-'
            - - !Ref Environment
sns.yml#L28
    Type: AWS::SNS::Topic
    Properties:
      TopicName: !Sub lip-budget-sns-topic-${Env}
      Subscription:
        - Endpoint: toshiki.hashida@lixil.com
          Protocol: email
cpp-support.yml#L11
    Type: AWS::SNS::Topic
    Properties:
      DisplayName: CPP Stage Support
      TopicName: cpp-stage-s1-support
      Subscription:
        - Endpoint: gdp-cpp@seekasia.com
initialTemplate.json#L9
            "Type": "AWS::SNS::TopicPolicy",
            "Properties": {
                "PolicyDocument": {
                    "Version": "2012-10-17",
                    "Statement": [
                        {
sata-sns-topics.json#L9
            "Type" : "AWS::SNS::Topic",
            "Properties" : {
                "Subscription" : [
                    { "Endpoint" : "rick@stackarmor.com", "Protocol" : "email" },
                    { "Endpoint" : "terry@stackarmor.com", "Protocol" : "email" },
                    { "Endpoint" : "kelley@stackarmor.com", "Protocol" : "email" },
Core-StandardTopics.json#L8
      "Type" : "AWS::SNS::Topic",
      "Properties" : {
        "TopicName" : "Administrators",
        "DisplayName" : "Administrators"
      }
    },
Core-StandardTopics.json#L8
      "Type" : "AWS::SNS::Topic",
      "Properties" : {
        "TopicName" : "Administrators",
        "DisplayName" : "Administrators"
      }
    },
Core-StandardTopics.json#L8
      "Type" : "AWS::SNS::Topic",
      "Properties" : {
        "TopicName" : "Administrators",
        "DisplayName" : "Administrators"
      }
    },

Parameters

Explanation in CloudFormation Registry

The AWS::SNS::Topic resource creates a topic to which notifications can be published.

Note One account can create a maximum of 100,000 standard topics and 1,000 FIFO topics. For more information, see Amazon SNS endpoints and quotas in the AWS General Reference.

Frequently asked questions

What is AWS Amazon SNS Topic?

AWS Amazon SNS Topic is a resource for Amazon SNS of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.

Where can I find the example code for the AWS Amazon SNS Topic?

For Terraform, the rhythmictech/terraform-aws-config-multiregion, devopsbynaresh/datalake-alsac and richinmedia/serverless-trivia-game source code examples are useful. See the Terraform Example section for further details.

For CloudFormation, the hcamusic/message, jayesh-20/wordpress and sammnike/Test source code examples are useful. See the CloudFormation Example section for further details.