amazon-web-servicesaws-glueamazon-snsaws-step-functions

How can I format and personalize the content of an AWS sns message?


I'm using sns service in a state machine that sends me a message when a glue job is failed or succeeded, and I don't want to sent me like all the json format, just a message that has the JobRunState parameter in it.

I already try to set the message I want to send on the sns state in the step function workflow like this:

{
  "message": "Job $.JobName Failed. Run id: $.Id"
}

but it does not read the parameters of the job


Solution

  • You need to do something like the following. First, the .$ suffix on the message key indicates that the value is a dynamic rather than static / literal. Second, Step Functions does not automatically interpolate that string and you need to use the States.Format intrinsic function.

    {
       "message.$": "States.Format('Job {} Failed. Run id: {}', $.JobName, $.Id)"
    }