🐾   [Amazon SNS] SNS 토픽을 구독한 메일로 메시지를 보낸다

메시지를 보내는 코드가 aws 홈페이지에 나와 있었다.

그래서 적용 시켜봤다.

토픽 리스트를 조회해서 내 이메일이 구독한 arn 주소와 메시지 내용을 보내 준다.


코드

func SendMessage(arn string, svc *sns.SNS) {
msgPtr := flag.String("m", "메시지내용", "The message to send to the subscribed users of the topic")
topicPtr := flag.String("t", arn, "The ARN of the topic to which the user subscribes")
flag.Parse()

result, err := svc.Publish(&sns.PublishInput{
Message:  msgPtr,
TopicArn: topicPtr,
})
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}

fmt.Println(*result.MessageId)
}

그럼 구독한 메일로 메시지가 온다.

참조

https://docs.aws.amazon.com/ko_kr/sdk-for-go/v1/developer-guide/sns-example-publish.html

​ ​ ​