A helper library for receiving Amazon AWS SNS HTTP(S) notifications.
It provides signature validation for payloads and conveinence functions for subscribing and unsubscribing from topics.
import (
"encoding/json"
"fmt"
"github.com/robbiet480/go.sns"
)
var notificationPayload sns.Payload
err := json.Unmarshal([]byte(notificationJson), ¬ificationPayload)
if err != nil {
fmt.Print(err)
}
verifyErr := notificationPayload.VerifyPayload()
if verifyErr != nil {
fmt.Print(verifyErr)
}
fmt.Print("Payload is valid!")
import (
"encoding/json"
"fmt"
"github.com/robbiet480/go.sns"
)
// If it's a SubscriptionConfirmation or UnsubscribeConfirmation
subscriptionResponse, err := notificationPayload.Subscribe()
if err != nil {
fmt.Println("Error when subscribing!", err)
}
fmt.Printf("subscriptionResponse %+v", subscriptionResponse)
import (
"encoding/json"
"fmt"
"github.com/robbiet480/go.sns"
)
// If it's a Notification
unsubscriptionResponse, err := notificationPayload.Unsubscribe()
if err != nil {
fmt.Println("Error when unsubscribing!", err)
}
fmt.Printf("unsubscriptionResponse %+v", unsubscriptionResponse)
This library was based off work by lazywei, found on this Stack Overflow question and code written by syama666.
Thanks also goes to xibz for helping me work out some of the low level certificate/SHA1WithRSA stuff in this issue on aws-sdk-go.
Fork, edit, write & run tests, submit PR, success!
Tests are written but not passing because the payload string is an example from the documentation.
MIT