github.com/mweagle/Sparta@v1.15.0/aws/step/sns.go (about) 1 package step 2 3 import ( 4 "math/rand" 5 6 gocf "github.com/mweagle/go-cloudformation" 7 ) 8 9 // SNSTaskParameters represents params for the SNS notification 10 // Ref: https://docs.aws.amazon.com/sns/latest/api/API_Publish.html#API_Publish_RequestParameters 11 type SNSTaskParameters struct { 12 Message string `json:",omitempty"` 13 Subject string `json:",omitempty"` 14 MessageAttributes map[string]interface{} `json:",omitempty"` 15 MessageStructure string `json:",omitempty"` 16 PhoneNumber string `json:",omitempty"` 17 TargetArn gocf.Stringable `json:",omitempty"` 18 TopicArn gocf.Stringable `json:",omitempty"` 19 } 20 21 // SNSTaskState represents bindings for 22 // https://docs.aws.amazon.com/step-functions/latest/dg/connectors-sns.html 23 type SNSTaskState struct { 24 BaseTask 25 parameters SNSTaskParameters 26 } 27 28 // MarshalJSON for custom marshalling, since this will be stringified and we need it 29 // to turn into a stringified 30 // Ref: https://docs.aws.amazon.com/step-functions/latest/dg/connectors-sns.html 31 func (sts *SNSTaskState) MarshalJSON() ([]byte, error) { 32 return sts.BaseTask.marshalMergedParams("arn:aws:states:::sns:publish", 33 &sts.parameters) 34 } 35 36 // NewSNSTaskState returns an initialized SNSTaskState 37 func NewSNSTaskState(stateName string, 38 parameters SNSTaskParameters) *SNSTaskState { 39 40 sns := &SNSTaskState{ 41 BaseTask: BaseTask{ 42 baseInnerState: baseInnerState{ 43 name: stateName, 44 id: rand.Int63(), 45 }, 46 }, 47 parameters: parameters, 48 } 49 return sns 50 }