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