Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subscribe to an SNS topic and / or SQS queue in golang?

I know how to do this in java, but I just can't figure it out in Go at all.

All I want to do, is have a way to detect that an item got created in an S3 bucket, then have that trigger an SNS topic, which then notifies me of the file location in S3.

Has anybody got a working example of how I can do the go side of this for subscribing to the SNS topic or the SNS queue if I need one? Because all I seem to be able to find is Java and Node. I can find publish examples for go, but they are of little use to my use case.

like image 721
MickeyThreeSheds Avatar asked Oct 28 '25 23:10

MickeyThreeSheds


1 Answers

To use SNS you will need a simple HTTP/HTTPS endpoint to receive SNS notifications. Which is divided into two parts (Confirm the subscription and Processing messages from HTTP/HTTPS endpoint)

1. Confirm the subscription Do something as simple as this:

func confirmSubscription(subcribeURL string) {
    response, err := http.Get(subcribeURL)
    if err != nil {
        fmt.Printf("Unbale to confirm subscriptions")
    } else {
        fmt.Printf("Subscription Confirmed sucessfully. %d", response.StatusCode)
    }
}

2. Processing messages from HTTP/HTTPS endpoint

Parse the request's body, the documentations mentions how the body should be structured.

Sources:

https://docs.aws.amazon.com/sns/latest/dg/sns-http-https-endpoint-as-subscriber.html

https://github.com/viveksyngh/aws-sns-subscriber/blob/master/subscriber/subscriber.go

like image 130
mostafazh Avatar answered Oct 30 '25 14:10

mostafazh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!