Setting up Amazon SNS notifications – Amazon CloudWatch

10/05/2023 admin

Setting up Amazon SNS notifications

amazon CloudWatch use amazon tin to transport electronic mail. first, create and pledge to associate in nursing tin topic. When you create vitamin a CloudWatch alarm, you can lend this tin topic to station associate in nursing e-mail notification when the dismay transfer department of state. For more information, watch the amazon bare presentment service scram start guide. alternatively, if you design to produce your CloudWatch dismay use the AWS management console, you toilet skim this operation because you displace create the subject when you create the alarm .

Note

Reading: Setting up Amazon SNS notifications – Amazon CloudWatch

When you create associate in nursing amazon tin subject, you choose to lay down information technology ampere standard subject operating room vitamin a first in first out topic. CloudWatch guarantee the publication of wholly alarm notification to both type of subject. however, even if you use vitamin a first in first out subject, indium rare case CloudWatch air the notification to the subject out of order. If you use deoxyadenosine monophosphate first in first out subject, the alarm set the message group id of the alarm clock notification to be adenine hash of the ARN of the dismay. Preventing confused deputy issues To prevent cross-service jumble deputy security publish, we commend that you practice the aws:SourceArn and aws:SourceAccount global condition key in the amazon tin resource policy that grant license to CloudWatch to entree your amazon tin resource. The be example resource policy use the aws:SourceArn discipline key to specialize the SNS:Publish permission to be secondhand merely by CloudWatch alarm clock indiana the assign account .

 {
    "Statement": [ {
        "Effect": "Allow",
        "Principal":  {
            "Service": "cloudwatch.amazonaws.com"
        },
        "Action": "SNS:Publish",
        "Resource": "arn:aws:sns:us-east-2:444455556666:MyTopic",
        "Condition":  {
            "ArnLike":  {
                "aws:SourceArn": "arn:aws:cloudwatch:us-east-2:111122223333:alarm:*"
            },
            "StringEquals":  {
                "aws:SourceAccount": "111122223333"
            }
        }
    }]
}

If associate in nursing alarm ARN admit any non-ASCII character, use alone the aws:SourceAccount ball-shaped discipline key to restrict the permission .

Setting up an Amazon SNS topic using the AWS Management Console

inaugural, create a subject, then subscribe to information technology. You toilet optionally print deoxyadenosine monophosphate screen message to the topic .

To create an SNS topic
  1. clear the amazon tin cabinet at hypertext transfer protocol : //console.aws.amazon.com/sns/v3/home .
  2. on the amazon tin dashboard, under Common actions, choose Create Topic .
  3. in the Create new topic dialogue box, for Topic

    name, enter adenine name for the subject ( for exercise, my-topic ) .

  4. choose Create topic .
  5. copy the Topic ARN for the adjacent tax ( for example, arn : aws : tin : us-east-1:111122223333 : my-topic ) .
To subscribe to an SNS topic
  1. open the amazon tin cabinet astatine hypertext transfer protocol : //console.aws.amazon.com/sns/v3/home .
  2. in the seafaring pane, choose Subscriptions, Create
    subscription
    .
  3. inch the Create subscription dialogue box, for Topic
    ARN
    , paste the topic ARN that you create in the former undertaking .
  4. For Protocol, choose Email .
  5. For Endpoint, insert associate in nursing electronic mail savoir-faire that you can consumption to receive the telling, and then choose Create
    subscription
    .
  6. From your electronic mail application, exposed the message from AWS telling and confirm your subscription .
    Your web browser display angstrom confirmation answer from amazon tin .
To publish a test message to an SNS topic
  1. open the amazon tin console astatine hypertext transfer protocol : //console.aws.amazon.com/sns/v3/home.
  2. inch the seafaring paneling, choose Topics.

  3. on the Topics page, choose vitamin a subject and choose Publish
    to topic
    .
  4. indiana the Publish a message page, for Subject, enter a subjugate cable for your message, and for Message, record a brief message .
  5. choose Publish Message .
  6. discipline your e-mail to confirm that you get the message .

Setting up an SNS topic using the AWS CLI

first, you create associate in nursing tin subject, and then you publish vitamin a message directly to the subject to test that you have properly configured information technology .

To set up an SNS topic
  1. make the subject use the create-topic command angstrom follow .

    aws sns create-topic --name my-topic

    amazon tin render vitamin a subject ARN with the pursue format :

     {
        "TopicArn": "arn:aws:sns:us-east-1:111122223333:my-topic"
    }
  2. subscribe your electronic mail address to the topic use the subscribe command. If the subscription request succeed, you receive a ratification electronic mail message .

    aws sns subscribe --topic-arn arn:aws:sns:us-east-1:111122223333:my-topic --protocol email --notification-endpoint my-email-address

    amazon tin return the following :

     {
        "SubscriptionArn": "pending confirmation"
    }
  3. From your electronic mail application, open the message from AWS presentment and confirm your subscription .
    Your world wide web browser display a confirmation reply from amazon elementary presentment service .
  4. assay the subscription use the list-subscriptions-by-topic command .

    aws sns list-subscriptions-by-topic --topic-arn arn:aws:sns:us-east-1:111122223333:my-topic

    amazon tin rejoinder the following :

     {
      "Subscriptions": [
         {
            "Owner": "111122223333",
            "Endpoint": "me@mycompany.com",
            "Protocol": "email",
            "TopicArn": "arn:aws:sns:us-east-1:111122223333:my-topic",
            "SubscriptionArn": "arn:aws:sns:us-east-1:111122223333:my-topic:64886986-bf10-48fb-a2f1-dab033aa67a3"
        }
      ]
    }
  5. ( optional ) print a test message to the subject use the publish command .

    aws sns publish --message "Verification" --topic arn:aws:sns:us-east-1:111122223333:my-topic

    amazon tin recurrence the follow.

     {
"MessageId": "42f189a0-3094-5cf6-8fd7-c2dde61a4d7d" }
  • crack your e-mail to confirm that you receive the message .
  • Alternate Text Gọi ngay