Lukasz_K_K
Lukasz_K_K

Reputation: 437

Send message to sqs while catch error in stepfunctions

i am using serverless framework with serverless-step-functions plugin. I want to check any errors in my stepfunction workflow and send this error to sqs queue.

Currently I want to pass all input as message to the queue(MessageBody: $). But if I get the data from the queue, message is $ (dollar sign) and not actual input. How can I send to queue the error message from the previous step?

  States:
    state1:
      Type: Task
      Resource:
        Fn::GetAtt: [function1, Arn]
      Next: state2
      Catch:
        - ErrorEquals: [States.ALL]
          Next: sendErrorToDLQ
          ResultPath: $.error
    state2:
      Type: Task
      Resource:
        Fn::GetAtt: [function2, Arn]
      Next: done
      Catch:
        - ErrorEquals: [ States.ALL ]
          Next: sendErrorToDLQ
          ResultPath: $.error
    sendErrorToDLQ:
      Type: Task
      Resource: arn:aws:states:::sqs:sendMessage
      Parameters:
        QueueUrl:
          Ref: ServiceDeadLetterQueue
        MessageBody: $    # <== how to pass input to sqs message
      Next: fail
    fail:
      Type: Fail
    done:
      Type: Succeed

Upvotes: 0

Views: 1695

Answers (1)

Muthu Thavamani
Muthu Thavamani

Reputation: 1405

I have got the same when connecting SNS. As per the AWS doc, we have to follow the below structure to send the parameters

"MessageBody.$": "$"

Reference: https://docs.aws.amazon.com/step-functions/latest/dg/connect-sqs.html

Upvotes: 2

Related Questions